From d5119eeeb2403f428cf7c47599232deb7acf94b9 Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Tue, 29 Aug 2023 11:26:46 +0200 Subject: [PATCH] Fix NonStupidDigestAssets with String whitelist We need to support Strings as well as Regexp. (cherry picked from commit de4c9742e1f3a26633cd825e9ded98b241de293a) --- lib/non_stupid_digest_assets.rb | 2 +- spec/libraries/non_stupid_digest_assets_spec.rb | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/non_stupid_digest_assets.rb b/lib/non_stupid_digest_assets.rb index e338499f27..033acdcb02 100644 --- a/lib/non_stupid_digest_assets.rb +++ b/lib/non_stupid_digest_assets.rb @@ -19,7 +19,7 @@ def assets(assets) def whitelisted_assets(assets) assets.select do |logical_path, _digest_path| whitelist.any? do |item| - item =~ logical_path + /#{item}/ =~ logical_path end end end diff --git a/spec/libraries/non_stupid_digest_assets_spec.rb b/spec/libraries/non_stupid_digest_assets_spec.rb index a81b6b309f..9cd0a2d2b9 100644 --- a/spec/libraries/non_stupid_digest_assets_spec.rb +++ b/spec/libraries/non_stupid_digest_assets_spec.rb @@ -14,11 +14,17 @@ end context "when the whitelist is not empty" do - it "returns the assets that match the whitelist" do + it "returns the assets that match the whitelist of regex" do NonStupidDigestAssets.whitelist = [/foo/] assets = { "foo.js" => "foo-123.js", "bar.js" => "bar-123.js" } expect(NonStupidDigestAssets.assets(assets)).to eq("foo.js" => "foo-123.js") end + + it "returns the assets that match the whitelist of strings" do + NonStupidDigestAssets.whitelist = ["foo.js"] + assets = {"foo.js" => "foo-123.js", "bar.js" => "bar-123.js"} + expect(NonStupidDigestAssets.assets(assets)).to eq("foo.js" => "foo-123.js") + end end end end