diff --git a/lib/sprockets/rails/sourcemapping_url_processor.rb b/lib/sprockets/rails/sourcemapping_url_processor.rb index fe8a29cc..5f25b911 100644 --- a/lib/sprockets/rails/sourcemapping_url_processor.rb +++ b/lib/sprockets/rails/sourcemapping_url_processor.rb @@ -23,7 +23,7 @@ def call(input) private def combine_sourcemap_logical_path(sourcefile:, sourcemap:) - if (parts = sourcefile.split("/")).many? + if (parts = sourcefile.split("/")).many? && !sourcemap.split("/").many? parts[0..-2].append(sourcemap).join("/") else sourcemap diff --git a/test/test_sourcemapping_url_processor.rb b/test/test_sourcemapping_url_processor.rb index ead7c33a..710be97e 100644 --- a/test/test_sourcemapping_url_processor.rb +++ b/test/test_sourcemapping_url_processor.rb @@ -46,4 +46,25 @@ def resolve(path, **kargs) output = Sprockets::Rails::SourcemappingUrlProcessor.call(input) assert_equal({ data: "var mapped;\n" }, output) end + + + def test_resolving_erroneously_with_prefix_path_on_filename + @env.context_class.class_eval do + def resolve(path, **kargs) + if(path == "subdir/mapped.js.map") + "assets/subdir/mapped.js.map" + else + raise Sprockets::FileNotFound + end + end + + def asset_path(path, options = {}) + "/assets/subdir/mapped-HEXGOESHERE.js.map" + end + end + + input = { environment: @env, data: "var mapped;\n//# sourceMappingURL=subdir/mapped.js.map", name: 'subdir/mapped', filename: 'subdir/mapped.js', metadata: {} } + output = Sprockets::Rails::SourcemappingUrlProcessor.call(input) + assert_equal({ data: "var mapped;\n//# sourceMappingURL=/assets/subdir/mapped-HEXGOESHERE.js.map\n//!\n" }, output) + end end