diff --git a/lib/propshaft/compiler/source_mapping_urls.rb b/lib/propshaft/compiler/source_mapping_urls.rb index d15e862..057de24 100644 --- a/lib/propshaft/compiler/source_mapping_urls.rb +++ b/lib/propshaft/compiler/source_mapping_urls.rb @@ -11,7 +11,7 @@ def compile(asset, input) private def asset_path(source_mapping_url, logical_path) - source_mapping_url.gsub!(/^(.+\/)?#{url_prefix}\//, "") + source_mapping_url = ::File.basename(source_mapping_url) if logical_path.dirname.to_s == "." source_mapping_url diff --git a/test/fixtures/assets/mapped/nested/sourceMappingURL-already-prefixed-nested-with-subdirectory.js b/test/fixtures/assets/mapped/nested/sourceMappingURL-already-prefixed-nested-with-subdirectory.js new file mode 100644 index 0000000..82bc61b --- /dev/null +++ b/test/fixtures/assets/mapped/nested/sourceMappingURL-already-prefixed-nested-with-subdirectory.js @@ -0,0 +1 @@ +var fun; //# sourceMappingURL=/assets/nested/sourceMappingURL-already-prefixed-nested-with-subdirectory.js.map diff --git a/test/fixtures/assets/mapped/nested/sourceMappingURL-already-prefixed-nested-with-subdirectory.js.map b/test/fixtures/assets/mapped/nested/sourceMappingURL-already-prefixed-nested-with-subdirectory.js.map new file mode 100644 index 0000000..e69de29 diff --git a/test/propshaft/compiler/source_mapping_urls_test.rb b/test/propshaft/compiler/source_mapping_urls_test.rb index ca06d20..f226b94 100644 --- a/test/propshaft/compiler/source_mapping_urls_test.rb +++ b/test/propshaft/compiler/source_mapping_urls_test.rb @@ -58,6 +58,8 @@ class Propshaft::Compiler::SourceMappingUrlsTest < ActiveSupport::TestCase compile_asset(find_asset("sourceMappingURL-already-prefixed.js", fixture_path: "mapped")) assert_match %r{//# sourceMappingURL=/assets/nested/sourceMappingURL-already-prefixed-nested-[a-z0-9]{8}\.js\.map}, compile_asset(find_asset("nested/sourceMappingURL-already-prefixed-nested.js", fixture_path: "mapped")) + assert_match %r{//# sourceMappingURL=/assets/nested/sourceMappingURL-already-prefixed-nested-with-subdirectory-[a-z0-9]{8}\.js\.map}, + compile_asset(find_asset("nested/sourceMappingURL-already-prefixed-nested-with-subdirectory.js", fixture_path: "mapped")) end test "sourceMapURL is already prefixed with an incorrect url_prefix" do