Skip to content
This repository was archived by the owner on Oct 22, 2020. It is now read-only.

Commit 61716c2

Browse files
committed
Improve version detection and replace use of fail with raise
1 parent 1749923 commit 61716c2

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

lib/wpxf/wordpress/fingerprint.rb

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,23 @@ def content_directory_name(type)
197197
when :theme
198198
return 'themes'
199199
else
200-
fail("Unknown readme type #{type}")
200+
raise("Unknown readme type #{type}")
201201
end
202202
end
203203

204+
def extract_highest_version(body, pattern)
205+
version = nil
206+
207+
body.scan(pattern) do |match|
208+
match_version = Gem::Version.new(match[0])
209+
version = match_version if version.nil? || match_version > version
210+
end
211+
212+
version
213+
end
214+
204215
def extract_and_check_version(body, pattern, fixed = nil, introduced = nil)
205-
version = body[pattern, 1]
216+
version = extract_highest_version(body, pattern)
206217
return :unknown if version.nil?
207218

208219
version = Gem::Version.new(version)
@@ -224,7 +235,7 @@ def extension_version_pattern(type)
224235
# Version: 1.5.2
225236
return /(?:Version):\s*([0-9a-z.-]+)/i
226237
else
227-
fail("Unknown file type #{type}")
238+
raise("Unknown file type #{type}")
228239
end
229240
end
230241
end

0 commit comments

Comments
 (0)