Skip to content

Commit 83d58a8

Browse files
committed
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
1 parent cc19b37 commit 83d58a8

File tree

4 files changed

+7
-1
lines changed

4 files changed

+7
-1
lines changed

lib/propshaft/compiler/source_mapping_urls.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def compile(logical_path, input)
1111

1212
private
1313
def asset_path(source_mapping_url, logical_path)
14-
source_mapping_url.gsub!(/^\/?#{url_prefix}\//, "")
14+
source_mapping_url.gsub!(/^(.+\/)?#{url_prefix}\//, "")
1515

1616
if logical_path.dirname.to_s == "."
1717
source_mapping_url
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
var fun; //# sourceMappingURL=thisisinvalidassets/sourceMappingURL-already-prefixed-invalid.js.map

test/fixtures/assets/mapped/sourceMappingURL-already-prefixed-invalid.js.map

Whitespace-only changes.

test/propshaft/compiler/source_mapping_urls_test.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ class Propshaft::Compiler::SourceMappingUrlsTest < ActiveSupport::TestCase
6060
compile_asset(find_asset("nested/sourceMappingURL-already-prefixed-nested.js", fixture_path: "mapped"))
6161
end
6262

63+
test "sourceMapURL is already prefixed with an incorrect url_prefix" do
64+
refute_match %r{//# sourceMappingURL=thisisinvalidassets/sourceMappingURL-already-prefixed-invalid.js-[a-z0-9]{40}\.map},
65+
compile_asset(find_asset("sourceMappingURL-already-prefixed-invalid.js", fixture_path: "mapped"))
66+
end
67+
6368
test "relative url root" do
6469
@options.relative_url_root = "/url-root"
6570

0 commit comments

Comments
 (0)