version: preserve semantic version separators - #662
Merged
Conversation
SemVer separates pre-release identifiers and build metadata with periods, but semanticAlphabet omits the period. String() treats normalizeVerString as a validator and only appends build metadata when the string round-trips unchanged, so a dot-separated stamp is dropped from the version entirely rather than reported. appBuild is settable at build time via -ldflags, and SemVer build metadata is dot-separated, so a build stamped exp.sha.5114f85 reports 0.22.2 instead of 0.22.2+exp.sha.5114f85. Add the period and extend TestString with a dotted build case.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
SemVer separates pre-release identifiers and build metadata with periods, but
semanticAlphabetomits the period.String()usesnormalizeVerStringas a validator rather than a sanitizer — it only appends the metadata when the string round-trips unchanged:So a dot-separated build stamp is not mangled, it is dropped from the version entirely, as if it had never been set. Adding a case to
TestStringshows it on master:This is reachable rather than latent.
appBuildis documented as settable at build time via-ldflags, and SemVer build metadata is dot-separated —exp.sha.5114f85is an example from the spec itself. The same applies toAppPreRelease: a value likebeta.rc1would be dropped rather than reported.The existing
with-out-of-spec-buildcase (012_abc, underscore) still passes, so genuinely invalid metadata is still rejected.btcd, which this code came from, fixed its copy in 65db493 ("version: preserve semantic version separators", btcsuite/btcd#2578).
go build ./...,go test ./version/,gofmtandgo vetare clean.One thing I noticed but left alone to keep the diff to the fix: the comment above
appBuildsays-X main.appBuild, but this copy lives in packageversion, so the flag is really-X github.com/gcash/bchd/version.appBuild. It was accurate before the code moved out ofmain.Disclosure: written with AI assistance; the analysis, fix and test were verified locally.