From cba6e74b13c594e1771b525014e0f1fd21e7d22a Mon Sep 17 00:00:00 2001 From: erwanlr Date: Sat, 18 Jul 2020 13:35:53 +0200 Subject: [PATCH] Fixes #1520 --- app/models/theme.rb | 2 +- spec/app/models/theme_spec.rb | 6 ++++++ spec/fixtures/models/theme/no_tags.css | 3 +++ 3 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 spec/fixtures/models/theme/no_tags.css diff --git a/app/models/theme.rb b/app/models/theme.rb index e55bf9b7a..37da6c915 100644 --- a/app/models/theme.rb +++ b/app/models/theme.rb @@ -101,7 +101,7 @@ def parse_style # # @return [ String ] def parse_style_tag(body, tag) - value = body[/#{Regexp.escape(tag)}:[\t ]*([^\r\n*]+)/i, 1] + value = body[/\b#{Regexp.escape(tag)}:[\t ]*([^\r\n*]+)/, 1] value && !value.strip.empty? ? value.strip : nil end diff --git a/spec/app/models/theme_spec.rb b/spec/app/models/theme_spec.rb index e86dd2296..7ea6c0def 100644 --- a/spec/app/models/theme_spec.rb +++ b/spec/app/models/theme_spec.rb @@ -41,6 +41,12 @@ its(:style_uri) { should eql 'http://www.elegantthemes.com/gallery/divi/' } its(:license_uri) { should eql 'http://www.gnu.org/licenses/gpl-2.0.html' } end + + context 'when no tags' do + let(:fixture) { fixtures.join('no_tags.css') } + + its(:author) { should eql nil } + end end describe '#version' do diff --git a/spec/fixtures/models/theme/no_tags.css b/spec/fixtures/models/theme/no_tags.css new file mode 100644 index 000000000..bf4fb827d --- /dev/null +++ b/spec/fixtures/models/theme/no_tags.css @@ -0,0 +1,3 @@ +comment-author:before,.comment-author:after,.widget-area:before,.widget-area:after,.widget:before,.widget:after { + /* Some style */ +}