FIX: do not raise exception when svg path is nil (#13844)

Bug was introduced here: f7ab852e12

If path is nil, it should not raise an exception and continue logging the error.
This commit is contained in:
Krzysztof Kotlarek 2021-07-26 12:35:27 +10:00 committed by GitHub
parent 6db93e86d4
commit 88aa0136e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 1 deletions

View File

@ -180,10 +180,10 @@ class ThemeField < ActiveRecord::Base
path = Discourse.store.path_for(upload)
end
content = File.read(path)
error = nil
begin
content = File.read(path)
svg_file = Nokogiri::XML(content) do |config|
config.options = Nokogiri::XML::ParseOptions::NOBLANKS
end

View File

@ -430,6 +430,11 @@ HTML
theme_field.destroy!
expect(SvgSprite.custom_svg_sprites(theme.id).size).to eq(0)
end
it 'crashes gracefully when svg is invalid' do
FileStore::LocalStore.any_instance.stubs(:path_for).returns(nil)
expect(theme_field.validate_svg_sprite_xml).to match("Error with icons-sprite")
end
end
end