Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support project roots with special characters #717

Merged
merged 1 commit into from May 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/simplecov/source_file.rb
Expand Up @@ -84,7 +84,7 @@ def initialize(filename, coverage)

# The path to this source file relative to the projects directory
def project_filename
@filename.sub(/^#{SimpleCov.root}/, "")
@filename.sub(Regexp.new("^#{Regexp.escape(SimpleCov.root)}"), "")
end

# The source code for this file. Aliased as :source
Expand Down
19 changes: 19 additions & 0 deletions spec/source_file_spec.rb
Expand Up @@ -22,6 +22,25 @@
expect(subject.project_filename).to eq("/spec/fixtures/sample.rb")
end

context "when project_root contains special characters" do
let(:root) { File.expand_path("foo[]bar") }

around do |example|
old_root = SimpleCov.root
SimpleCov.root(root)
begin
example.run
ensure
SimpleCov.root(old_root)
end
end

it "works" do
source_file = SimpleCov::SourceFile.new(File.expand_path("sample.rb", root), COVERAGE_FOR_SAMPLE_RB)
expect(source_file.project_filename).to eq("/sample.rb")
end
end

it "has source_lines equal to lines" do
expect(subject.lines).to eq(subject.source_lines)
end
Expand Down