Skip to content

Commit

Permalink
Prevent damage to /* ... */ comments with missing source maps (#132)
Browse files Browse the repository at this point in the history
  • Loading branch information
pond authored May 7, 2023
1 parent a8bbfd8 commit 69c285f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/propshaft/compilers/source_mapping_urls.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def source_mapping_url(resolved_path, comment)
"#{comment}# sourceMappingURL=#{assembly.config.prefix}/#{asset.digested_path}"
else
Propshaft.logger.warn "Removed sourceMappingURL comment for missing asset '#{resolved_path}' from #{resolved_path}"
nil
comment
end
end
end
7 changes: 6 additions & 1 deletion test/propshaft/compilers/source_mapping_urls_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class Propshaft::Compilers::SourceMappingUrlsTest < ActiveSupport::TestCase
setup do
@assembly = Propshaft::Assembly.new(ActiveSupport::OrderedOptions.new.tap { |config|
@assembly = Propshaft::Assembly.new(ActiveSupport::OrderedOptions.new.tap { |config|
config.paths = [ Pathname.new("#{__dir__}/../../fixtures/assets/mapped") ]
config.output_path = Pathname.new("#{__dir__}/../../fixtures/output")
config.prefix = "/assets"
Expand Down Expand Up @@ -35,6 +35,11 @@ class Propshaft::Compilers::SourceMappingUrlsTest < ActiveSupport::TestCase
@assembly.compilers.compile(find_asset("sourceless.css", fixture_path: "mapped"))
end

test "sourceMappingURL removal due to missing map does not damage /* ... */ comments" do
assert_match %r{\A#{Regexp.escape ".failure { color: red; }\n/* */\n"}\Z},
@assembly.compilers.compile(find_asset("sourceless.css", fixture_path: "mapped"))
end

test "sourceMappingURL outside of a comment should be left alone" do
assert_match %r{sourceMappingURL=sourceMappingURL-outside-comment.css.map},
@assembly.compilers.compile(find_asset("sourceMappingURL-outside-comment.css", fixture_path: "mapped"))
Expand Down

0 comments on commit 69c285f

Please sign in to comment.