From 1c4b1423c00179facf8c6acdd35b4a2c8715ee64 Mon Sep 17 00:00:00 2001 From: WarningImHack3r <43064022+WarningImHack3r@users.noreply.github.com> Date: Mon, 29 Dec 2025 01:23:20 +0100 Subject: [PATCH 1/3] Fix additional trailing zeros being counted as version upgrade --- Sources/mas/Utilities/Version+SemVer.swift | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Sources/mas/Utilities/Version+SemVer.swift b/Sources/mas/Utilities/Version+SemVer.swift index 6f181554..443192d0 100644 --- a/Sources/mas/Utilities/Version+SemVer.swift +++ b/Sources/mas/Utilities/Version+SemVer.swift @@ -157,6 +157,16 @@ struct UniversalSemVer: SemVerSyntax { } } +extension Collection { + func dropLast(while predicate: (Element) throws -> Bool) rethrows -> SubSequence { + guard let index = try indices.reversed().first(where: { try !predicate(self[$0]) }) else { + return self[startIndex.. ComparisonResult { self < that ? .orderedAscending : self == that ? .orderedSame : .orderedDescending @@ -186,7 +196,11 @@ private extension String { private extension [String] { func compareSemVerElements(to that: Self) -> ComparisonResult { - zip(self, that).first { $0 != $1 }.map { $0.compareSemVerElement(to: $1) } ?? (count.compare(to: that.count)) + zip(self, that) + .first { $0 != $1 } + .map { $0.compareSemVerElement(to: $1) } + ?? dropLast(while: { $0 == "0" }).count + .compare(to: that.dropLast(while: { $0 == "0" }).count) } } From d00b5abddc1fea4db0be3e8f2b08ac032dc78b3e Mon Sep 17 00:00:00 2001 From: WarningImHack3r <43064022+WarningImHack3r@users.noreply.github.com> Date: Mon, 29 Dec 2025 01:32:51 +0100 Subject: [PATCH 2/3] Fix formatting --- Sources/mas/Utilities/Version+SemVer.swift | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Sources/mas/Utilities/Version+SemVer.swift b/Sources/mas/Utilities/Version+SemVer.swift index 443192d0..8782d0d6 100644 --- a/Sources/mas/Utilities/Version+SemVer.swift +++ b/Sources/mas/Utilities/Version+SemVer.swift @@ -158,12 +158,12 @@ struct UniversalSemVer: SemVerSyntax { } extension Collection { - func dropLast(while predicate: (Element) throws -> Bool) rethrows -> SubSequence { - guard let index = try indices.reversed().first(where: { try !predicate(self[$0]) }) else { - return self[startIndex.. Bool) rethrows -> SubSequence { + guard let index = try indices.reversed().first(where: { try !predicate(self[$0]) }) else { + return self[startIndex.. Date: Mon, 29 Dec 2025 01:16:59 -0500 Subject: [PATCH 3/3] Move `dropLast(while:)` to `Collection.swift`. Reformat code. Signed-off-by: Ross Goldberg <484615+rgoldberg@users.noreply.github.com> --- Sources/mas/Utilities/Collection.swift | 6 ++++++ Sources/mas/Utilities/Version+SemVer.swift | 17 ++--------------- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/Sources/mas/Utilities/Collection.swift b/Sources/mas/Utilities/Collection.swift index ee686d35..87e0ad94 100644 --- a/Sources/mas/Utilities/Collection.swift +++ b/Sources/mas/Utilities/Collection.swift @@ -5,6 +5,12 @@ // Copyright © 2025 mas-cli. All rights reserved. // +extension Collection { + func dropLast(while predicate: (Element) throws -> Bool) rethrows -> SubSequence { + try indices.reversed().first { try !predicate(self[$0]) }.map { self[...$0] } ?? self[endIndex...] + } +} + extension Collection { func compactMap(_ transform: (Element) async throws(E) -> T?) async throws(E) -> [T] { var transformedElements = [T]() diff --git a/Sources/mas/Utilities/Version+SemVer.swift b/Sources/mas/Utilities/Version+SemVer.swift index 8782d0d6..f2f52cbb 100644 --- a/Sources/mas/Utilities/Version+SemVer.swift +++ b/Sources/mas/Utilities/Version+SemVer.swift @@ -157,16 +157,6 @@ struct UniversalSemVer: SemVerSyntax { } } -extension Collection { - func dropLast(while predicate: (Element) throws -> Bool) rethrows -> SubSequence { - guard let index = try indices.reversed().first(where: { try !predicate(self[$0]) }) else { - return self[startIndex.. ComparisonResult { self < that ? .orderedAscending : self == that ? .orderedSame : .orderedDescending @@ -196,11 +186,8 @@ private extension String { private extension [String] { func compareSemVerElements(to that: Self) -> ComparisonResult { - zip(self, that) - .first { $0 != $1 } - .map { $0.compareSemVerElement(to: $1) } - ?? dropLast(while: { $0 == "0" }).count - .compare(to: that.dropLast(while: { $0 == "0" }).count) + zip(self, that).first { $0 != $1 }.map { $0.compareSemVerElement(to: $1) } + ?? dropLast { $0 == "0" }.count.compare(to: that.dropLast { $0 == "0" }.count) // swiftformat:disable:this indent } }