Skip to content

Commit 69c285f

Browse files
authored
Prevent damage to /* ... */ comments with missing source maps (#132)
1 parent a8bbfd8 commit 69c285f

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

lib/propshaft/compilers/source_mapping_urls.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def source_mapping_url(resolved_path, comment)
2727
"#{comment}# sourceMappingURL=#{assembly.config.prefix}/#{asset.digested_path}"
2828
else
2929
Propshaft.logger.warn "Removed sourceMappingURL comment for missing asset '#{resolved_path}' from #{resolved_path}"
30-
nil
30+
comment
3131
end
3232
end
3333
end

test/propshaft/compilers/source_mapping_urls_test.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

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

38+
test "sourceMappingURL removal due to missing map does not damage /* ... */ comments" do
39+
assert_match %r{\A#{Regexp.escape ".failure { color: red; }\n/* */\n"}\Z},
40+
@assembly.compilers.compile(find_asset("sourceless.css", fixture_path: "mapped"))
41+
end
42+
3843
test "sourceMappingURL outside of a comment should be left alone" do
3944
assert_match %r{sourceMappingURL=sourceMappingURL-outside-comment.css.map},
4045
@assembly.compilers.compile(find_asset("sourceMappingURL-outside-comment.css", fixture_path: "mapped"))

0 commit comments

Comments
 (0)