diff --git a/lib/common/models/wp_theme/findable.rb b/lib/common/models/wp_theme/findable.rb
index 172fd2ccf..cdd13b455 100755
--- a/lib/common/models/wp_theme/findable.rb
+++ b/lib/common/models/wp_theme/findable.rb
@@ -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
@@ -50,7 +47,6 @@ def find_from_wooframework(target_uri)
body = Browser.get(target_uri.to_s).body
regexp = %r{\s+}
-
if matches = regexp.match(body)
woo_theme_name = matches[1]
woo_theme_version = matches[2]
@@ -58,10 +54,8 @@ def find_from_wooframework(target_uri)
return new(
target_uri,
- {
- name: woo_theme_name,
- version: woo_theme_version
- }
+ name: woo_theme_name,
+ version: woo_theme_version
)
end
end
diff --git a/spec/lib/common/models/wp_theme/findable_spec.rb b/spec/lib/common/models/wp_theme/findable_spec.rb
index 29f412cb8..113ffa1c0 100644
--- a/spec/lib/common/models/wp_theme/findable_spec.rb
+++ b/spec/lib/common/models/wp_theme/findable_spec.rb
@@ -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
@@ -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