From 6ebb9b6f66a626a98274686aa4f17b5c59f8d24f Mon Sep 17 00:00:00 2001 From: Christian Mehlmauer Date: Wed, 16 Jul 2014 18:25:35 +0200 Subject: [PATCH] Fixed false positive theme detection --- lib/common/models/wp_theme.rb | 9 ++--- lib/common/models/wp_theme/findable.rb | 4 +-- lib/common/models/wp_theme/output.rb | 1 + .../common/models/wp_theme/findable_spec.rb | 7 ++++ spec/lib/common/models/wp_theme_spec.rb | 15 +------- .../wp_theme/findable/css_link/yootheme.html | 36 +++++++++++++++++++ 6 files changed, 50 insertions(+), 22 deletions(-) create mode 100644 spec/samples/common/models/wp_theme/findable/css_link/yootheme.html diff --git a/lib/common/models/wp_theme.rb b/lib/common/models/wp_theme.rb index 6cafa982..6f840a09 100755 --- a/lib/common/models/wp_theme.rb +++ b/lib/common/models/wp_theme.rb @@ -15,9 +15,9 @@ class WpTheme < WpItem include WpTheme::Output include WpTheme::Childtheme - attr_writer :style_url + attr_accessor :additional_url - def allowed_options; super << :style_url end + def allowed_options; super << :additional_url end def initialize(*args) super(*args) @@ -36,10 +36,7 @@ class WpTheme < WpItem # @return [ String ] The url to the theme stylesheet def style_url - unless @style_url - @style_url = uri.merge('style.css').to_s - end - @style_url + uri.merge('style.css').to_s end end diff --git a/lib/common/models/wp_theme/findable.rb b/lib/common/models/wp_theme/findable.rb index cc7c20ff..033ac4a0 100755 --- a/lib/common/models/wp_theme/findable.rb +++ b/lib/common/models/wp_theme/findable.rb @@ -30,13 +30,13 @@ class WpTheme < WpItem response = Browser.get_and_follow_location(target_uri.to_s) # https + domain is optional because of relative links - matches = %r{(?:https?://[^"']+)?/([^/]+)/themes/([^"']+)/style.css}i.match(response.body) + matches = /(?:https?:\/\/[^"']+)?\/([^\/]+)\/themes\/([^"'\/]+)[^"']*\/style.css/i.match(response.body) if matches return new( target_uri, { name: matches[2], - style_url: matches[0], + additional_url: matches[0], wp_content_dir: matches[1] } ) diff --git a/lib/common/models/wp_theme/output.rb b/lib/common/models/wp_theme/output.rb index eb1d7b9b..f806dc7a 100644 --- a/lib/common/models/wp_theme/output.rb +++ b/lib/common/models/wp_theme/output.rb @@ -7,6 +7,7 @@ class WpTheme def additional_output(verbose = false) theme_desc = verbose ? @theme_description : truncate(@theme_description, 100) puts " | Style URL: #{style_url}" + puts " | Additional URL: #{additional_url}" if additional_url puts " | Theme Name: #@theme_name" if @theme_name puts " | Theme URI: #@theme_uri" if @theme_uri puts " | Description: #{theme_desc}" diff --git a/spec/lib/common/models/wp_theme/findable_spec.rb b/spec/lib/common/models/wp_theme/findable_spec.rb index fc160d02..1554492f 100644 --- a/spec/lib/common/models/wp_theme/findable_spec.rb +++ b/spec/lib/common/models/wp_theme/findable_spec.rb @@ -52,6 +52,13 @@ describe 'WpTheme::Findable' do end end + context 'when other style.css is referenced' do + it 'returns the WpTheme' do + @file = 'yootheme.html' + @expected = WpTheme.new(uri, name: 'yoo_solar_wp') + end + end + end describe '::find_from_wooframework' do diff --git a/spec/lib/common/models/wp_theme_spec.rb b/spec/lib/common/models/wp_theme_spec.rb index e8d79334..3b99e6d1 100644 --- a/spec/lib/common/models/wp_theme_spec.rb +++ b/spec/lib/common/models/wp_theme_spec.rb @@ -29,24 +29,11 @@ describe WpTheme do let(:theme_path) { 'wp-content/themes/theme-name/' } describe '#allowed_options' do - its(:allowed_options) { is_expected.to include :style_url } + its(:allowed_options) { is_expected.to include :additional_url } end describe '#forge_uri' do its(:uri) { is_expected.to eq uri.merge(theme_path) } end - describe '#style_url' do - its(:style_url) { is_expected.to eq uri.merge(theme_path + '/style.css').to_s } - - context 'when its already set' do - it 'returns it instead of the default one' do - url = uri.merge(theme_path + '/custom.css').to_s - wp_theme.style_url = url - - expect(wp_theme.style_url).to eq url - end - end - end - end diff --git a/spec/samples/common/models/wp_theme/findable/css_link/yootheme.html b/spec/samples/common/models/wp_theme/findable/css_link/yootheme.html new file mode 100644 index 00000000..03a90db7 --- /dev/null +++ b/spec/samples/common/models/wp_theme/findable/css_link/yootheme.html @@ -0,0 +1,36 @@ + + + + + + + + +XXXXX + + + + + + + + + + + + + + + + + + + + + + + + + + +