Skip to content

A platform for community discussion. Free, open, simple.

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

Krzysztof Kotlarek88aa0136e372
diff --git a/app/models/theme_field.rb b/app/models/theme_field.rb
index 847745642c2..603e1f0eaf0 100644
--- a/app/models/theme_field.rb
+++ b/app/models/theme_field.rb
@@ -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
diff --git a/spec/models/theme_field_spec.rb b/spec/models/theme_field_spec.rb
index 9854ce3084a..5ebc77dc478 100644
--- a/spec/models/theme_field_spec.rb
+++ b/spec/models/theme_field_spec.rb
@@ -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