diff --git a/lib/svg_sprite/svg_sprite.rb b/lib/svg_sprite/svg_sprite.rb index 79bef31f366..b2010fe4105 100644 --- a/lib/svg_sprite/svg_sprite.rb +++ b/lib/svg_sprite/svg_sprite.rb @@ -330,6 +330,11 @@ License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL end custom_svg_sprites(theme_ids).each do |fname| + if !File.exist?(fname) + cache.delete("custom_svg_sprites_#{Theme.transform_ids(theme_ids).join(',')}") + next + end + svg_file = Nokogiri::XML(File.open(fname)) do |config| config.options = Nokogiri::XML::ParseOptions::NOBLANKS end @@ -354,6 +359,8 @@ License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL searched_icon = process(searched_icon.dup) sprite_sources([SiteSetting.default_theme_id]).each do |fname| + next if !File.exist?(fname) + svg_file = Nokogiri::XML(File.open(fname)) svg_filename = "#{File.basename(fname, ".svg")}" @@ -375,6 +382,8 @@ License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL results = Set.new sprite_sources([SiteSetting.default_theme_id]).each do |fname| + next if !File.exist?(fname) + svg_file = Nokogiri::XML(File.open(fname)) svg_filename = "#{File.basename(fname, ".svg")}" @@ -475,6 +484,8 @@ License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL # Automatically register icons in sprites added via themes or plugins icons = [] custom_svg_sprites(theme_ids).each do |fname| + next if !File.exist?(fname) + svg_file = Nokogiri::XML(File.open(fname)) svg_file.css('symbol').each do |sym| diff --git a/spec/components/svg_sprite/svg_sprite_spec.rb b/spec/components/svg_sprite/svg_sprite_spec.rb index abb39b1a3f8..bce38204419 100644 --- a/spec/components/svg_sprite/svg_sprite_spec.rb +++ b/spec/components/svg_sprite/svg_sprite_spec.rb @@ -165,7 +165,15 @@ describe SvgSprite do before do setup_s3 - stub_request(:get, upload_s3.url).to_return(status: 200, body: "Hello world") + body = <<~XML + + + + + + + XML + stub_request(:get, upload_s3.url).to_return(status: 200, body: body) end it 'includes svg sprites in themes stored in s3' do @@ -174,9 +182,19 @@ describe SvgSprite do theme.save! sprite_files = SvgSprite.custom_svg_sprites([theme.id]).join("|") - expect(sprite_files).to match(/#{upload_s3.sha1}/) expect(sprite_files).not_to match(/amazonaws/) + + SvgSprite.bundle([theme.id]) + expect(SvgSprite.cache.hash.keys).to include("custom_svg_sprites_#{theme.id}") + + external_copy = Discourse.store.download(upload_s3) + File.delete external_copy.try(:path) + + SvgSprite.bundle([theme.id]) + # when a file is missing, ensure that cache entry is cleared + expect(SvgSprite.cache.hash.keys).to_not include("custom_svg_sprites_#{theme.id}") + end end