diff --git a/lib/propshaft/compiler/css_asset_urls.rb b/lib/propshaft/compiler/css_asset_urls.rb index 5e9a737..c2c68c0 100644 --- a/lib/propshaft/compiler/css_asset_urls.rb +++ b/lib/propshaft/compiler/css_asset_urls.rb @@ -3,7 +3,7 @@ require "propshaft/compiler" class Propshaft::Compiler::CssAssetUrls < Propshaft::Compiler - ASSET_URL_PATTERN = /url\(\s*["']?(?!(?:\#|%23|data|http|\/\/))([^"'\s?#)]+)([#?][^"')]+)?\s*["']?\)/ + ASSET_URL_PATTERN = /url\(\s*["']?(?!(?:\#|%23|data:|http:|https:|\/\/))([^"'\s?#)]+)([#?][^"')]+)?\s*["']?\)/ def compile(asset, input) input.gsub(ASSET_URL_PATTERN) { asset_url resolve_path(asset.logical_path.dirname, $1), asset.logical_path, $2, $1 } diff --git a/test/fixtures/assets/vendor/foobar/source/database.jpg b/test/fixtures/assets/vendor/foobar/source/database.jpg new file mode 100644 index 0000000..5aa9c1e Binary files /dev/null and b/test/fixtures/assets/vendor/foobar/source/database.jpg differ diff --git a/test/fixtures/assets/vendor/foobar/source/http-diagram.jpg b/test/fixtures/assets/vendor/foobar/source/http-diagram.jpg new file mode 100644 index 0000000..5aa9c1e Binary files /dev/null and b/test/fixtures/assets/vendor/foobar/source/http-diagram.jpg differ diff --git a/test/propshaft/compiler/css_asset_urls_test.rb b/test/propshaft/compiler/css_asset_urls_test.rb index 3b672ad..41e6980 100644 --- a/test/propshaft/compiler/css_asset_urls_test.rb +++ b/test/propshaft/compiler/css_asset_urls_test.rb @@ -76,6 +76,9 @@ class Propshaft::Compiler::CssAssetUrlsTest < ActiveSupport::TestCase test "url" do compiled = compile_asset_with_content(%({ background: url('https://rubyonrails.org/images/rails-logo.svg'); })) assert_match "{ background: url('https://rubyonrails.org/images/rails-logo.svg'); }", compiled + + compiled = compile_asset_with_content(%({ background: url(http-diagram.jpg); })) + assert_match(/{ background: url\("\/assets\/foobar\/source\/http-diagram-[a-z0-9]{8}.jpg"\); }/, compiled) end test "relative protocol url" do @@ -86,6 +89,9 @@ class Propshaft::Compiler::CssAssetUrlsTest < ActiveSupport::TestCase test "data" do compiled = compile_asset_with_content(%({ background: url(data:image/png;base64,iRxVB0); })) assert_match "{ background: url(data:image/png;base64,iRxVB0); }", compiled + + compiled = compile_asset_with_content(%({ background: url(database.jpg); })) + assert_match(/{ background: url\("\/assets\/foobar\/source\/database-[a-z0-9]{8}.jpg"\); }/, compiled) end test "anchor" do