Skip to content

Commit

Permalink
Swallow anything after file extension in css asset urls
Browse files Browse the repository at this point in the history
  • Loading branch information
brenogazzola committed Feb 17, 2022
1 parent 4433b73 commit 1396c0a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/propshaft/compilers/css_asset_urls.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class Propshaft::Compilers::CssAssetUrls
attr_reader :assembly

ASSET_URL_PATTERN = /url\(\s*["']?(?!(?:\#|data|http))([^"'\s)]+)\s*["']?\)/
ASSET_URL_PATTERN = /url\(\s*["']?(?!(?:\#|data|http))([^"'\s?#)]+)([#?][^"']+)?\s*["']?\)/

def initialize(assembly)
@assembly = assembly
Expand Down
10 changes: 10 additions & 0 deletions test/propshaft/compilers/css_asset_urls_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,16 @@ class Propshaft::Compilers::CssAssetUrlsTest < ActiveSupport::TestCase
assert_match "{ background: url(#IDofSVGpath); }", compiled
end

test "fingerprint" do
compiled = compile_asset_with_content(%({ background: url('/file.jpg?30af91bf14e37666a085fb8a161ff36d'); }))
assert_match(/{ background: url\("\/assets\/file-[a-z0-9]{40}.jpg"\); }/, compiled)
end

test "hash symbol" do
compiled = compile_asset_with_content(%({ background: url('/file.jpg#fontawesome'); }))
assert_match(/{ background: url\("\/assets\/file-[a-z0-9]{40}.jpg"\); }/, compiled)
end

test "missing asset" do
compiled = compile_asset_with_content(%({ background: url("file-not-found.jpg"); }))
assert_match(/{ background: url\("file-not-found.jpg"\); }/, compiled)
Expand Down

0 comments on commit 1396c0a

Please sign in to comment.