New Upstream Release - ruby-sprockets-rails
Ready changes
Summary
Merged new upstream version: 3.4.2 (was: 3.4.1).
Diff
diff --git a/README.md b/README.md
index 6972092..d2f17ff 100644
--- a/README.md
+++ b/README.md
@@ -86,7 +86,7 @@ When enabled, fingerprints will be added to asset filenames.
**`config.assets.debug`**
-Enable expanded asset debugging mode. Individual files will be served to make referencing filenames in the web console easier. This feature will eventually be deprecated and replaced by Source Maps in Sprockets 3.x.
+Enable asset debugging mode. A source map will be included with each asset when this is true.
**`config.assets.compile`**
@@ -108,6 +108,10 @@ config.assets.configure do |env|
end
```
+**`config.assets.resolve_assets_in_css_urls`**
+
+When this option is enabled, sprockets-rails will register a CSS postprocessor to resolve assets referenced in [`url()`](https://developer.mozilla.org/en-US/docs/Web/CSS/url()) function calls and replace them with the digested paths. Defaults to `true`.
+
**`config.assets.resolve_with`**
A list of `:environment` and `:manifest` symbols that defines the order that
diff --git a/debian/changelog b/debian/changelog
index 618b87f..fb062a6 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
+ruby-sprockets-rails (3.4.2-1) UNRELEASED; urgency=low
+
+ * New upstream release.
+
+ -- Debian Janitor <janitor@jelmer.uk> Sun, 09 Apr 2023 18:53:14 -0000
+
ruby-sprockets-rails (3.4.1-2) unstable; urgency=medium
* Team upload
diff --git a/lib/sprockets/rails/asset_url_processor.rb b/lib/sprockets/rails/asset_url_processor.rb
index 7739f43..7adcb9e 100644
--- a/lib/sprockets/rails/asset_url_processor.rb
+++ b/lib/sprockets/rails/asset_url_processor.rb
@@ -1,8 +1,8 @@
module Sprockets
module Rails
- # Rewrites urls in CSS files with the digested paths
+ # Resolve assets referenced in CSS `url()` calls and replace them with the digested paths
class AssetUrlProcessor
- REGEX = /url\(\s*["']?(?!(?:\#|data|http))(?<relativeToCurrentDir>.\/)?(?<path>[^"'\s)]+)\s*["']?\)/
+ REGEX = /url\(\s*["']?(?!(?:\#|data|http))(?<relativeToCurrentDir>\.\/)?(?<path>[^"'\s)]+)\s*["']?\)/
def self.call(input)
context = input[:environment].context_class.new(input)
data = input[:data].gsub(REGEX) do |_match|
diff --git a/lib/sprockets/rails/version.rb b/lib/sprockets/rails/version.rb
index 5a9baf2..ae65877 100644
--- a/lib/sprockets/rails/version.rb
+++ b/lib/sprockets/rails/version.rb
@@ -1,5 +1,5 @@
module Sprockets
module Rails
- VERSION = "3.4.1"
+ VERSION = "3.4.2"
end
end
diff --git a/lib/sprockets/railtie.rb b/lib/sprockets/railtie.rb
index 5651faf..1ebfaa6 100644
--- a/lib/sprockets/railtie.rb
+++ b/lib/sprockets/railtie.rb
@@ -97,12 +97,13 @@ module Sprockets
end
config.assets = OrderedOptions.new
- config.assets._blocks = []
- config.assets.paths = []
- config.assets.precompile = []
- config.assets.prefix = "/assets"
- config.assets.manifest = nil
- config.assets.quiet = false
+ config.assets._blocks = []
+ config.assets.paths = []
+ config.assets.precompile = []
+ config.assets.prefix = "/assets"
+ config.assets.manifest = nil
+ config.assets.quiet = false
+ config.assets.resolve_assets_in_css_urls = true
initializer :set_default_precompile do |app|
if using_sprockets4?
@@ -120,7 +121,9 @@ module Sprockets
end
initializer :asset_url_processor do |app|
- Sprockets.register_postprocessor "text/css", ::Sprockets::Rails::AssetUrlProcessor
+ if app.config.assets.resolve_assets_in_css_urls
+ Sprockets.register_postprocessor "text/css", ::Sprockets::Rails::AssetUrlProcessor
+ end
end
initializer :asset_sourcemap_url_processor do |app|
diff --git a/test/test_asset_url_processor.rb b/test/test_asset_url_processor.rb
index d9fbd70..7b1bdac 100644
--- a/test/test_asset_url_processor.rb
+++ b/test/test_asset_url_processor.rb
@@ -61,4 +61,10 @@ class TestAssetUrlProcessor < Minitest::Test
jquery_digest = 'c6910e1db4a5ed4905be728ab786471e81565f4a9d544734b199f3790de9f9a3'
assert_equal("background: url(/jquery/jquery-#{jquery_digest}.js);", output[:data])
end
+
+ def test_protocol_relative_paths
+ input = { environment: @env, data: "background: url(//assets.example.com/assets/fontawesome-webfont-82ff0fe46a6f60e0ab3c4a9891a0ae0a1f7b7e84c625f55358379177a2dcb202.eot);", filename: 'url2.css', metadata: {} }
+ output = Sprockets::Rails::AssetUrlProcessor.call(input)
+ assert_equal("background: url(//assets.example.com/assets/fontawesome-webfont-82ff0fe46a6f60e0ab3c4a9891a0ae0a1f7b7e84c625f55358379177a2dcb202.eot);", output[:data])
+ end
end
diff --git a/test/test_railtie.rb b/test/test_railtie.rb
index c24b237..6eb1c82 100644
--- a/test/test_railtie.rb
+++ b/test/test_railtie.rb
@@ -423,6 +423,23 @@ class TestRailtie < TestBoot
assert middleware.each_cons(2).include?([Sprockets::Rails::QuietAssets, Rails::Rack::Logger])
end
+ def test_resolve_assets_in_css_urls_defaults_to_true
+ app.initialize!
+
+ assert_equal true, app.config.assets.resolve_assets_in_css_urls
+ assert_includes Sprockets.postprocessors['text/css'], Sprockets::Rails::AssetUrlProcessor
+ end
+
+ def test_resolve_assets_in_css_urls_when_false_avoids_registering_postprocessor
+ app.configure do
+ config.assets.resolve_assets_in_css_urls = false
+ end
+ app.initialize!
+
+ assert_equal false, app.config.assets.resolve_assets_in_css_urls
+ refute_includes Sprockets.postprocessors['text/css'], Sprockets::Rails::AssetUrlProcessor
+ end
+
private
def action_view
ActionView::Base.new(ActionView::LookupContext.new([]), {}, nil)