From 6d21df2c8bbc41903e409d2d67b21cbc312e4d13 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sun, 6 Dec 2020 20:04:53 +0100 Subject: [PATCH] Always choose longer version in correct format. --- Library/Homebrew/dev-cmd/bump-unversioned-casks.rb | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/dev-cmd/bump-unversioned-casks.rb b/Library/Homebrew/dev-cmd/bump-unversioned-casks.rb index f4a68963c..8d720e10b 100644 --- a/Library/Homebrew/dev-cmd/bump-unversioned-casks.rb +++ b/Library/Homebrew/dev-cmd/bump-unversioned-casks.rb @@ -258,8 +258,17 @@ module Homebrew return cask.version.to_s if [short_version, version].include?(cask.version.to_s) - return short_version if short_version&.match(/\A\d+(\.\d+)+\Z/) - return version if version&.match(/\A\d+(\.\d+)+\Z/) + short_version_match = short_version&.match?(/\A\d+(\.\d+)+\Z/) + version_match = version&.match?(/\A\d+(\.\d+)+\Z/) + + if short_version_match && version_match + return version if version.length > short_version.length && version.start_with?(short_version) + return short_version if short_version.length > version.length && short_version.start_with?(version) + elsif short_version_match + return short_version + elsif version_match + return version + end short_version || version end