Skip to content

v0.3.1 — no method on a zero-value Version panics

Latest

Choose a tag to compare

@jonyoder jonyoder released this 07 Aug 18:49
· 26 commits to main since this release
448c491

Eight of the thirteen exported methods on Version panicked on a zero value — including all six comparison methods, since Compare uses String as its equality fast path. A zero Version now renders as "", sorts below every parsed version, and two zero values compare equal.

Three separate defects, each verified load-bearing by reverting it alone:

  1. String and BaseVersion indexed release[0] on a nil slice.
  2. real.Compare(Version{}) dereferenced nil even after (1): a zero comparison key holds nil Part interfaces and Parts.IsAny ranges over them without a nil check. Asymmetric — Version{}.Compare(real) returned an answer while the reverse crashed, which is what showed this was a second, distinct defect.
  3. Compare padded the second release segment to its own length rather than the longer of the two. Latent only: parsed-version behavior was already correct, verified across nine pairs with differing segment counts in both directions.

Fixed, not Breaking. Every changed path previously panicked, so no caller can depend on it. Parsed-version behavior is unchanged.

⚠️ Worth knowing generally: fmt recovers a panic raised inside a String method and substitutes %!s(PANIC=...). This class of bug is therefore invisible wherever the value is formatted into a message, and fatal only where String() is called directly. That is why rstudio/package-manager#19466's F14 identified the wrong function.