From 6aa7cda4787569ef4d93d157f36d190d2ec5cd67 Mon Sep 17 00:00:00 2001 From: erwanlr Date: Sat, 5 Oct 2019 20:25:35 +0100 Subject: [PATCH] Fixes #1404 --- app/models/theme.rb | 2 +- spec/app/models/theme_spec.rb | 15 +++++++++++---- spec/fixtures/models/theme/stripped_new_lines.css | 9 +++++++++ 3 files changed, 21 insertions(+), 5 deletions(-) create mode 100644 spec/fixtures/models/theme/stripped_new_lines.css diff --git a/app/models/theme.rb b/app/models/theme.rb index 79635de6..b6a48ab3 100644 --- a/app/models/theme.rb +++ b/app/models/theme.rb @@ -101,7 +101,7 @@ module WPScan # # @return [ String ] def parse_style_tag(body, tag) - value = body[/^\s*#{Regexp.escape(tag)}:[\t ]*([^\r\n]+)/i, 1] + value = body[/#{Regexp.escape(tag)}:[\t ]*([^\r\n\*]+)/i, 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 c2d631cc..51505309 100644 --- a/spec/app/models/theme_spec.rb +++ b/spec/app/models/theme_spec.rb @@ -10,10 +10,9 @@ describe WPScan::Model::Theme do before { expect(blog).to receive(:content_dir).at_least(1).and_return('wp-content') } describe '#new' do - before do - stub_request(:get, /.*\.css\z/) - .to_return(body: File.read(fixtures.join('style.css'))) - end + before { stub_request(:get, /.*\.css\z/).to_return(body: File.read(fixture)) } + + let(:fixture) { fixtures.join('style.css') } its(:url) { should eql 'http://wp.lab/wp-content/themes/spec/' } its(:style_url) { should eql 'http://wp.lab/wp-content/themes/spec/style.css' } @@ -34,6 +33,14 @@ describe WPScan::Model::Theme do its(:style_url) { should eql opts[:style_url] } end + + context 'when some new lines are stripped' do + let(:fixture) { fixtures.join('stripped_new_lines.css') } + + its(:style_name) { should eql 'Divi' } + 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 end describe '#version' do diff --git a/spec/fixtures/models/theme/stripped_new_lines.css b/spec/fixtures/models/theme/stripped_new_lines.css new file mode 100644 index 00000000..2c31861e --- /dev/null +++ b/spec/fixtures/models/theme/stripped_new_lines.css @@ -0,0 +1,9 @@ +/*!Theme Name: Divi +Theme URI: http://www.elegantthemes.com/gallery/divi/ +Version: 3.29.3 +Description: Smart. Flexible. Beautiful. Divi is the most powerful theme in our collection. +Author: Elegant Themes +Author URI: http://www.elegantthemes.com +Tags: responsive-layout, one-column, two-columns, three-columns, four-columns, left-sidebar, right-sidebar, custom-background, custom-colors, featured-images, full-width-template, post-formats, rtl-language-support, theme-options, threaded-comments, translation-ready +License: GNU General Public License v2 +License URI: http://www.gnu.org/licenses/gpl-2.0.html*/a,abbr,acronym,address,applet,b,big,blockquote,body