Run of fresh-releases for ruby-sprockets-rails

Merge these changes:

git pull https://janitor.debian.net/git/ruby-sprockets-rails fresh-releases/main
git pull https://janitor.debian.net/git/ruby-sprockets-rails fresh-releases/pristine-tar
git pull https://janitor.debian.net/git/ruby-sprockets-rails fresh-releases/upstream

Summary

Merged new upstream version: 3.4.2 (was: 3.4.1).

Diff

Branch: main

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 dc9e24e..9d5e08d 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>  Wed, 16 Mar 2022 11:50:43 -0000
+
 ruby-sprockets-rails (3.4.1-1) 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)

Branch: pristine-tar

diff --git a/ruby-sprockets-rails_3.4.2.orig.tar.gz.delta b/ruby-sprockets-rails_3.4.2.orig.tar.gz.delta
new file mode 100644
index 0000000..988c95a
Binary files /dev/null and b/ruby-sprockets-rails_3.4.2.orig.tar.gz.delta differ
diff --git a/ruby-sprockets-rails_3.4.2.orig.tar.gz.id b/ruby-sprockets-rails_3.4.2.orig.tar.gz.id
new file mode 100644
index 0000000..84e89e3
--- /dev/null
+++ b/ruby-sprockets-rails_3.4.2.orig.tar.gz.id
@@ -0,0 +1 @@
+9e09a08de1d253e4a9d86bd07bfcfa2b17b83b68

Branch: upstream

Tag: upstream/3.4.2
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/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)

Publish Blockers

  • ☑ run was successful
  • ☑ package has not been removed from the archive
  • ☑ command has not changed
  • ☒ not yet reviewed, but review needed
  • ☑ 0 publish attempts so far.not currently attempting to back off
  • ☒ merge proposals for the package maintainer are currently being rate-limited (open: 1253, max open: 200)
  • ☑ change set 075a170e-7b03-4310-bd37-3441d7fd13c9 is ready

Resulting package

The resulting binary packages can be installed (if you have the apt repository enabled) by running one of:

apt install -t fresh-releases ruby-sprockets-rails

Lintian Result

Full worker log Full build log