Skip to content

Commit

Permalink
capture possible cdn host
Browse files Browse the repository at this point in the history
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
  • Loading branch information
tagCincy committed Dec 12, 2023
1 parent cc19b37 commit 83d58a8
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/propshaft/compiler/source_mapping_urls.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
var fun; //# sourceMappingURL=thisisinvalidassets/sourceMappingURL-already-prefixed-invalid.js.map
Empty file.
5 changes: 5 additions & 0 deletions test/propshaft/compiler/source_mapping_urls_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down

0 comments on commit 83d58a8

Please sign in to comment.