Skip to content

Fix numeric prerelease comparisons with leading zeroes - #228

Closed
xianjianlf2 wants to merge 1 commit into
hashicorp:mainfrom
xianjianlf2:fix/prerelease-leading-zero-20261012
Closed

xianjianlf2 wants to merge 1 commit into
hashicorp:mainfrom
xianjianlf2:fix/prerelease-leading-zero-20261012

Conversation

@xianjianlf2

Copy link
Copy Markdown
Contributor

Description

NewVersion accepts numeric prerelease identifiers with leading zeroes, but the numeric comparison uses their untrimmed lengths. This makes 1.0.0-001 compare greater than 1.0.0-2, and 1.0.0-01 compare unequal to 1.0.0-1.

Trim leading zeroes before comparing numeric identifiers. This preserves support for values larger than int64 without changing parsing or the original version strings.

Related Issue

No linked issue.

How Has This Been Tested?

Regression tests cover equal values, all-zero identifiers, ordering, and values larger than int64 in both comparison directions. Five of the seven cases fail before the fix.

Passing after the fix:

  • go test -race -count=1 ./...
  • go vet ./...
  • git diff --check

Code, tests, and this draft were prepared with OpenAI Codex.

@xianjianlf2
xianjianlf2 requested a review from a team as a code owner October 12, 2026 09:08
@hashicorp-cla-app

hashicorp-cla-app Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@tgross tgross 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.

Generally speaking we're not interested in getting a pile of LLM-generated fixes that aren't motivated by specific problems in HashiCorp products or spec compliance issues. How do you suggest this changeset interacts with the following bit from section 9 of the semver spec:

Numeric identifiers MUST NOT include leading zeroes.

Especially given that you changed the docstring in the process.

@tgross

tgross commented Oct 13, 2026

Copy link
Copy Markdown
Member

If your response to questions on a PR is to close it without comment, please do us a favor and don't bother opening more slop PRs. We're really only interested in developing human contributors, not encouraging LLM slop.

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