Skip to content

Commit 6a84a8c

Browse files
authored
Fix CSS Asset Compiler to work with files started with data and http (#224)
1 parent 1cfc401 commit 6a84a8c

File tree

4 files changed

+7
-1
lines changed

4 files changed

+7
-1
lines changed

lib/propshaft/compiler/css_asset_urls.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
require "propshaft/compiler"
44

55
class Propshaft::Compiler::CssAssetUrls < Propshaft::Compiler
6-
ASSET_URL_PATTERN = /url\(\s*["']?(?!(?:\#|%23|data|http|\/\/))([^"'\s?#)]+)([#?][^"')]+)?\s*["']?\)/
6+
ASSET_URL_PATTERN = /url\(\s*["']?(?!(?:\#|%23|data:|http:|https:|\/\/))([^"'\s?#)]+)([#?][^"')]+)?\s*["']?\)/
77

88
def compile(asset, input)
99
input.gsub(ASSET_URL_PATTERN) { asset_url resolve_path(asset.logical_path.dirname, $1), asset.logical_path, $2, $1 }
375 Bytes
Loading
375 Bytes
Loading

test/propshaft/compiler/css_asset_urls_test.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ class Propshaft::Compiler::CssAssetUrlsTest < ActiveSupport::TestCase
7676
test "url" do
7777
compiled = compile_asset_with_content(%({ background: url('https://rubyonrails.org/images/rails-logo.svg'); }))
7878
assert_match "{ background: url('https://rubyonrails.org/images/rails-logo.svg'); }", compiled
79+
80+
compiled = compile_asset_with_content(%({ background: url(http-diagram.jpg); }))
81+
assert_match(/{ background: url\("\/assets\/foobar\/source\/http-diagram-[a-z0-9]{8}.jpg"\); }/, compiled)
7982
end
8083

8184
test "relative protocol url" do
@@ -86,6 +89,9 @@ class Propshaft::Compiler::CssAssetUrlsTest < ActiveSupport::TestCase
8689
test "data" do
8790
compiled = compile_asset_with_content(%({ background: url(data:image/png;base64,iRxVB0); }))
8891
assert_match "{ background: url(data:image/png;base64,iRxVB0); }", compiled
92+
93+
compiled = compile_asset_with_content(%({ background: url(database.jpg); }))
94+
assert_match(/{ background: url\("\/assets\/foobar\/source\/database-[a-z0-9]{8}.jpg"\); }/, compiled)
8995
end
9096

9197
test "anchor" do

0 commit comments

Comments
 (0)