-
-
Notifications
You must be signed in to change notification settings - Fork 408
fix: normalize build numbers #8568
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -94,7 +94,7 @@ public final class Updater: Sendable { | |
| components.queryItems?.append(URLQueryItem(name: "build_version", value: shortVersionString)) | ||
| } | ||
| if let bundleVersion = Bundle.main.infoDictionary?["CFBundleVersion"] as? String { | ||
| components.queryItems?.append(URLQueryItem(name: "build_number", value: bundleVersion)) | ||
| components.queryItems?.append(URLQueryItem(name: "build_number", value: normalizeBuildNumber(bundleVersion))) | ||
| } | ||
| if let installGroups = params.installGroupsOverride { | ||
| for group in installGroups { | ||
|
|
@@ -115,6 +115,33 @@ public final class Updater: Sendable { | |
| } | ||
| } | ||
|
|
||
| private func normalizeBuildNumber(_ buildNumber: String) -> String { | ||
| let components = buildNumber.split(separator: ".", omittingEmptySubsequences: false) | ||
| guard (2...3).contains(components.count), | ||
| components.allSatisfy({ component in | ||
| !component.isEmpty && component.allSatisfy(\.isNumber) | ||
| }) else { | ||
| return buildNumber | ||
| } | ||
|
|
||
| // Sentry stores each version component in a six-digit base-1,000,000 slot. | ||
| let componentBase: UInt64 = 1_000_000 | ||
| let numericComponents = components.compactMap { UInt64($0) } | ||
| guard numericComponents.count == components.count, | ||
| numericComponents.allSatisfy({ $0 < componentBase }) else { | ||
| return buildNumber | ||
| } | ||
|
|
||
| let paddedComponents = numericComponents + Array( | ||
| repeating: 0, | ||
| count: 3 - numericComponents.count) | ||
| let normalizedBuildNumber = paddedComponents.reduce(UInt64(0)) { result, component in | ||
| result * componentBase + component | ||
| } | ||
|
|
||
| return String(normalizedBuildNumber) | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing tests for build normalizationMedium Severity
Reviewed by Cursor Bugbot for commit 29cfb3d. Configure here. |
||
|
|
||
| // MARK: - Private | ||
| static let shared = Updater() | ||
| private let session: URLSession | ||
|
|
||


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: The
normalizeBuildNumberfunction fails to normalize single-component build numbers (e.g., "42"), returning the raw string instead of the expected format required by the API.Severity: HIGH
Suggested Fix
Modify the guard condition in
normalizeBuildNumberto accept single-component version strings by changing the check to(1...3).contains(components.count). Then, adjust the logic to correctly pad and convert single-component numbers into the required base-1,000,000 format, ensuring they are handled consistently with multi-component versions.Prompt for AI Agent
Did we get this right? π / π to inform future reviews.