alphanumeric identifier in prerelease version should be allowed to have a leading 0
oocx opened this issue · comments
According to https://semver.org/#spec-item-9, the limitation that leading zeros are not allowed applies to numeric identifiers, not alphanumeric identifiers. However, currently alphanumeric identifiers with a leading 0 are rejected as "invalid" as well.
For example, we use major.minor.patch-commitHash as version number for our helm charts. This currently fails if the commit hash randomly happens to start with a 0.
I've reported this as a bug in helm (helm/helm#7064), the helm maintainers asked me to open a ticket here.
Could you please fix this? Or is my understanding of the semver spec wrong?
Regards
Mathias
@oocx can you provide some examples that are failing as bugs. The one on the Helm issue was a number that started with 0 and did not contain characters outside of 0-9. Therefore it's a number in terms of the spec. A commit hash can be a number.
The section of code in semver that validates pre-release segments can be found at
Lines 579 to 592 in 49c09bf
@mattfarina An alphanumeric identifier is not required to contain letters, it can consist of numbers only, including a leading 0. The spec even provides a regular expression.
Identifiers MUST comprise only ASCII alphanumerics and hyphens [0-9A-Za-z-]
I think the spec could be interpreted in both ways. I'll ask in the semver repo for a clarification.
@mattfarina I found the answer: while the spec text is ambiguous, there is actually a BNF that defines what valid values are: https://semver.org/#backusnaur-form-grammar-for-valid-semver-versions
According to this spec, an alphanumeric identifier must always contain at least one non-digit character.
<alphanumeric identifier> ::= <non-digit>
| <non-digit> <identifier characters>
| <identifier characters> <non-digit>
| <identifier characters> <non-digit> <identifier characters>
So your implementation is correct according to the spec. Sorry for bothering you with this issue.