Skip to content

version: fix asymmetric trailing zero comparison - #24569

Open
hyuraku wants to merge 1 commit into
Homebrew:mainfrom
hyuraku:version-asymmetric-comparison
Open

hyuraku wants to merge 1 commit into
Homebrew:mainfrom
hyuraku:version-asymmetric-comparison

Conversation

@hyuraku

@hyuraku hyuraku commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor
brew ruby -e 'p [Version.new("1.0.0") <=> Version.new("1.0rc1"), Version.new("1.0rc1") <=> Version.new("1.0.0")]'
# before: [0, -1]
# after:  [1, -1]

The loop stops when the left index reaches the end, so after skipping a padding 0 it never compares the right side's rc1. Now it runs until both sides reach the end. Because of this bug, brew outdated does not
treat 1.0.0 as newer than an installed 1.0rc1.

Only pairs that were already asymmetric change, and each one now matches the swapped call. I checked this on all pairs of generated strings and of the formula and cask versions in the API data. I added a test for this case.


  • Have you followed our Contributing guidelines?
  • Have you checked for other open Pull Requests for the same change?
  • Have you explained what your changes do? Performance claims (e.g. "this is faster") must include brew benchmark results.
  • Have you explained why you'd like these changes included, not just what they do?
  • For bug fixes, have you given step-by-step brew commands to reproduce the bug?
  • Have you written new tests (excluding integration tests)? Here's an example.
  • Have you successfully run brew lgtm (style, typechecking and tests) locally?

  • I did not use AI/LLM to create this PR, or I disclosed the tool/model below and reviewed its output; every commit has a human author or co-author and I will answer maintainer questions and review comments myself without AI/LLM.

AI (Claude Code) found this bug with a script that checks ordering laws on many version strings, and drafted the fix and test. I reviewed the change and ran brew lgtm locally.


@coderabbitai

coderabbitai Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Bug Fixes
    • Corrected version comparisons so that a stable release sorts after its release candidate.

Version#<=> now compares tokens until both versions are exhausted. A test checks that release 1.0.0 sorts after release candidate 1.0rc1.

Changes: Version comparison

Layer / File(s) Summary
Token comparison and regression test
Library/Homebrew/version.rb, Library/Homebrew/test/version_spec.rb
Version#<=> continues comparing tokens until both lists are exhausted. The test asserts that 1.0.0 sorts after 1.0rc1.
Merge Risk: Minimal · up to c5039

This change makes version comparison symmetric, so 1.0.0 is correctly treated as newer than 1.0rc1. No actionable merge risk remains.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title clearly identifies the main change: fixing asymmetric version comparison involving trailing zeroes.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The description clearly explains the version comparison bug, the code change, its effect on brew outdated, and the added test. It directly matches the changeset.
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 938f3b80-c00b-42aa-a802-6b5b58be864f
Commits

Reviewing files that changed from the base of the PR and between 2ea376f and c503942.

Files selected for processing: 2

  • Library/Homebrew/test/version_spec.rb
  • Library/Homebrew/version.rb

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@MikeMcQuaid MikeMcQuaid left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@MikeMcQuaid
MikeMcQuaid added this pull request to the merge queue Nov 11, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 11, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants