Skip to content

Commit

Permalink
Backport 'Fix error when SVG icon is not available in the file system…
Browse files Browse the repository at this point in the history
…' to v0.27 (#11007)

Co-authored-by: Antti Hukkanen <antti.hukkanen@mainiotech.fi>
  • Loading branch information
alecslupu and ahukkanen committed Jun 15, 2023
1 parent 1f5541b commit 2d35213
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
5 changes: 4 additions & 1 deletion decidim-core/app/helpers/decidim/layout_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,10 @@ def application_path(path)
# non-nil because otherwise it will be set to the asset host at
# ActionView::Helpers::AssetUrlHelper#compute_asset_host.
img_path = asset_pack_path(path, host: "", protocol: :relative)
Rails.public_path.join(img_path.sub(%r{^/}, ""))
path = Rails.public_path.join(img_path.sub(%r{^/}, ""))
return unless File.exist?(path)

path
rescue ::Webpacker::Manifest::MissingEntryError
nil
end
Expand Down
24 changes: 24 additions & 0 deletions decidim-core/spec/helpers/decidim/layout_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@ module Decidim
end
end

context "when the icon exists in the manifest but not in the file system" do
let(:path) { "media/images/google.svg" }

before do
allow(helper).to receive(:asset_pack_path).and_return("/unexisting/path.svg")
end

it "returns nil" do
expect(subject).to be_nil
end
end

context "when using a custom host" do
let(:path) { "media/images/google.svg" }

Expand Down Expand Up @@ -63,6 +75,18 @@ module Decidim
end
end

context "when the icon exists in the manifest but not in the file system" do
let(:path) { "media/images/google.svg" }

before do
allow(helper).to receive(:asset_pack_path).and_return("/unexisting/path.svg")
end

it "returns nil" do
expect(subject).to be_nil
end
end

context "when using a custom host" do
let(:path) { "media/images/google.svg" }

Expand Down

0 comments on commit 2d35213

Please sign in to comment.