Updates the Theme detection pattern - Fixes #804

This commit is contained in:
erwanlr
2015-04-15 18:37:23 +01:00
parent a4bbf41086
commit deb8508ea5
2 changed files with 18 additions and 19 deletions

View File

@@ -30,18 +30,15 @@ class WpTheme < WpItem
response = Browser.get_and_follow_location(target_uri.to_s) response = Browser.get_and_follow_location(target_uri.to_s)
# https + domain is optional because of relative links # https + domain is optional because of relative links
matches = /(?:https?:\/\/[^"']+)?\/([^\/]+)\/themes\/([^"'\/]+)[^"']*\/style.css/i.match(response.body) return unless response.body =~ %r{(?:https?://[^"']+)?/?([^/\s]+)/themes/([^"'/]+)[^"']*/style.css}i
if matches
return new( new(
target_uri, target_uri,
{ name: Regexp.last_match[2],
name: matches[2], referenced_url: Regexp.last_match[0],
referenced_url: matches[0], wp_content_dir: Regexp.last_match[1]
wp_content_dir: matches[1]
}
) )
end end
end
# @param [ URI ] target_uri # @param [ URI ] target_uri
# #
@@ -50,7 +47,6 @@ class WpTheme < WpItem
body = Browser.get(target_uri.to_s).body body = Browser.get(target_uri.to_s).body
regexp = %r{<meta name="generator" content="([^\s"]+)\s?([^"]+)?" />\s+<meta name="generator" content="WooFramework\s?([^"]+)?" />} regexp = %r{<meta name="generator" content="([^\s"]+)\s?([^"]+)?" />\s+<meta name="generator" content="WooFramework\s?([^"]+)?" />}
if matches = regexp.match(body) if matches = regexp.match(body)
woo_theme_name = matches[1] woo_theme_name = matches[1]
woo_theme_version = matches[2] woo_theme_version = matches[2]
@@ -58,10 +54,8 @@ class WpTheme < WpItem
return new( return new(
target_uri, target_uri,
{
name: woo_theme_name, name: woo_theme_name,
version: woo_theme_version version: woo_theme_version
}
) )
end end
end end

View File

@@ -17,9 +17,7 @@ describe 'WpTheme::Findable' do
wp_theme = WpTheme.send(:find_from_css_link, uri) wp_theme = WpTheme.send(:find_from_css_link, uri)
if @expected expect(wp_theme).to be_a WpTheme if @expected
expect(wp_theme).to be_a WpTheme
end
expect(wp_theme).to eq @expected expect(wp_theme).to eq @expected
end end
@@ -59,6 +57,13 @@ describe 'WpTheme::Findable' do
end end
end end
# This one might introduce FP btw
context 'when leaked from comments' do
it 'returns the WpTheme' do
@file = 'comments.html'
@expected = WpTheme.new(uri, name: 'debug')
end
end
end end
describe '::find_from_wooframework' do describe '::find_from_wooframework' do