Skip to content

Commit

Permalink
Updates the Theme detection pattern - Fixes #804
Browse files Browse the repository at this point in the history
  • Loading branch information
erwanlr committed Apr 15, 2015
1 parent a4bbf41 commit deb8508
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
26 changes: 10 additions & 16 deletions lib/common/models/wp_theme/findable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,14 @@ def find_from_css_link(target_uri)
response = Browser.get_and_follow_location(target_uri.to_s)

# https + domain is optional because of relative links
matches = /(?:https?:\/\/[^"']+)?\/([^\/]+)\/themes\/([^"'\/]+)[^"']*\/style.css/i.match(response.body)
if matches
return new(
target_uri,
{
name: matches[2],
referenced_url: matches[0],
wp_content_dir: matches[1]
}
)
end
return unless response.body =~ %r{(?:https?://[^"']+)?/?([^/\s]+)/themes/([^"'/]+)[^"']*/style.css}i

new(
target_uri,
name: Regexp.last_match[2],
referenced_url: Regexp.last_match[0],
wp_content_dir: Regexp.last_match[1]
)
end

# @param [ URI ] target_uri
Expand All @@ -50,18 +47,15 @@ def find_from_wooframework(target_uri)
body = Browser.get(target_uri.to_s).body
regexp = %r{<meta name="generator" content="([^\s"]+)\s?([^"]+)?" />\s+<meta name="generator" content="WooFramework\s?([^"]+)?" />}


if matches = regexp.match(body)
woo_theme_name = matches[1]
woo_theme_version = matches[2]
#woo_framework_version = matches[3] # Not used at this time

return new(
target_uri,
{
name: woo_theme_name,
version: woo_theme_version
}
name: woo_theme_name,
version: woo_theme_version
)
end
end
Expand Down
11 changes: 8 additions & 3 deletions spec/lib/common/models/wp_theme/findable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@

wp_theme = WpTheme.send(:find_from_css_link, uri)

if @expected
expect(wp_theme).to be_a WpTheme
end
expect(wp_theme).to be_a WpTheme if @expected
expect(wp_theme).to eq @expected
end

Expand Down Expand Up @@ -59,6 +57,13 @@
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

describe '::find_from_wooframework' do
Expand Down

0 comments on commit deb8508

Please sign in to comment.