From 83d58a8d490d56c7b2ce4c80459112d2ca346140 Mon Sep 17 00:00:00 2001 From: Tim Guibord Date: Tue, 12 Dec 2023 08:08:38 -0500 Subject: [PATCH] capture possible cdn host in production environments the url_prefix may be proceeded by a cdn host, ensure that it is part of the capture group this change will require anything prior to the url_prefix to end in a forward slash test case --- lib/propshaft/compiler/source_mapping_urls.rb | 2 +- .../mapped/sourceMappingURL-already-prefixed-invalid.js | 1 + .../mapped/sourceMappingURL-already-prefixed-invalid.js.map | 0 test/propshaft/compiler/source_mapping_urls_test.rb | 5 +++++ 4 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/assets/mapped/sourceMappingURL-already-prefixed-invalid.js create mode 100644 test/fixtures/assets/mapped/sourceMappingURL-already-prefixed-invalid.js.map diff --git a/lib/propshaft/compiler/source_mapping_urls.rb b/lib/propshaft/compiler/source_mapping_urls.rb index 30e57d5..bad3f0e 100644 --- a/lib/propshaft/compiler/source_mapping_urls.rb +++ b/lib/propshaft/compiler/source_mapping_urls.rb @@ -11,7 +11,7 @@ def compile(logical_path, input) private def asset_path(source_mapping_url, logical_path) - source_mapping_url.gsub!(/^\/?#{url_prefix}\//, "") + source_mapping_url.gsub!(/^(.+\/)?#{url_prefix}\//, "") if logical_path.dirname.to_s == "." source_mapping_url diff --git a/test/fixtures/assets/mapped/sourceMappingURL-already-prefixed-invalid.js b/test/fixtures/assets/mapped/sourceMappingURL-already-prefixed-invalid.js new file mode 100644 index 0000000..a52b8dd --- /dev/null +++ b/test/fixtures/assets/mapped/sourceMappingURL-already-prefixed-invalid.js @@ -0,0 +1 @@ +var fun; //# sourceMappingURL=thisisinvalidassets/sourceMappingURL-already-prefixed-invalid.js.map diff --git a/test/fixtures/assets/mapped/sourceMappingURL-already-prefixed-invalid.js.map b/test/fixtures/assets/mapped/sourceMappingURL-already-prefixed-invalid.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 5decc09..05a4d7b 100644 --- a/test/propshaft/compiler/source_mapping_urls_test.rb +++ b/test/propshaft/compiler/source_mapping_urls_test.rb @@ -60,6 +60,11 @@ class Propshaft::Compiler::SourceMappingUrlsTest < ActiveSupport::TestCase compile_asset(find_asset("nested/sourceMappingURL-already-prefixed-nested.js", fixture_path: "mapped")) end + test "sourceMapURL is already prefixed with an incorrect url_prefix" do + refute_match %r{//# sourceMappingURL=thisisinvalidassets/sourceMappingURL-already-prefixed-invalid.js-[a-z0-9]{40}\.map}, + compile_asset(find_asset("sourceMappingURL-already-prefixed-invalid.js", fixture_path: "mapped")) + end + test "relative url root" do @options.relative_url_root = "/url-root"