Fix version mapping.

This commit is contained in:
Markus Reiter 2020-12-08 00:49:54 +01:00
parent e416668a25
commit 05b496194a
2 changed files with 8 additions and 10 deletions

View File

@ -16,6 +16,7 @@ describe Homebrew::UnversionedCaskChecker do
["1.0", "1"] => "1.0", ["1.0", "1"] => "1.0",
["1.0", "0"] => "1.0", ["1.0", "0"] => "1.0",
["1.2.3.4000", "4000"] => "1.2.3.4000", ["1.2.3.4000", "4000"] => "1.2.3.4000",
["5", "5.0.45"] => "5.0.45",
} }
expected_mappings.each do |(short_version, version), expected_version| expected_mappings.each do |(short_version, version), expected_version|

View File

@ -72,18 +72,15 @@ module Homebrew
def self.decide_between_versions(short_version, version) def self.decide_between_versions(short_version, version)
return short_version if short_version == version return short_version if short_version == version
short_version_match = short_version&.match?(/\A\d+(\.\d+)+\Z/) if short_version && version
version_match = version&.match?(/\A\d+(\.\d+)+\Z/) return version if version.match?(/\A\d+(\.\d+)+\Z/) && version.start_with?("#{short_version}.")
return short_version if short_version.match?(/\A\d+(\.\d+)+\Z/) && short_version.start_with?("#{version}.")
if short_version_match && version_match if short_version.match?(/\A\d+(\.\d+)*\Z/) && version.match?(/\A\d+\Z/)
return version if version.length > short_version.length && version.start_with?("#{short_version}.") return short_version if short_version.start_with?("#{version}.") || short_version.end_with?(".#{version}")
return short_version if short_version.length > version.length && short_version.start_with?("#{version}.")
end
if short_version&.match?(/\A\d+(\.\d+)*\Z/) && version&.match?(/\A\d+\Z/) return "#{short_version},#{version}"
return short_version if short_version.start_with?("#{version}.") || short_version.end_with?(".#{version}") end
return "#{short_version},#{version}"
end end
short_version || version short_version || version