[GH-ISSUE #583] May prerelease-version contain leading zeros? #5540

Open
opened 2026-06-15 12:01:48 -05:00 by GiteaMirror · 6 comments
Owner

Originally created by @Anaphory on GitHub (Jun 19, 2020).
Original GitHub issue: https://github.com/semver/semver/issues/583

There is some ambiguity in item 9:

[…] Numeric identifiers MUST NOT include leading zeroes. […] Examples: […] 1.0.0-0.3.7, […]

The BN grammar says

<pre-release> ::= <dot-separated pre-release identifiers>
<dot-separated pre-release identifiers> ::= <pre-release identifier>
                                          | <pre-release identifier> "." <dot-separated pre-release identifiers>
<pre-release identifier> ::= <alphanumeric identifier>
                           | <numeric identifier>
<numeric identifier> ::= "0"
                       | <positive digit>
                       | <positive digit> <digits>

So this seems to mean “Numeric identifiers MAY be "0", but MUST NOT be any other number with leading zeroes" or something like that? Assuming that is the intention. It would be nice to clarify the natural-language statement in one shape or another, and if that is not the intended meaning, ajdust the examples and the BN grammar.

Originally created by @Anaphory on GitHub (Jun 19, 2020). Original GitHub issue: https://github.com/semver/semver/issues/583 There is some ambiguity in [item 9](https://semver.org/#spec-item-9): > […] Numeric identifiers MUST NOT include leading zeroes. […] Examples: […] 1.0.0-0.3.7, […] The [BN grammar](https://semver.org/#backusnaur-form-grammar-for-valid-semver-versions) says > <pre-release> ::= <dot-separated pre-release identifiers> > <dot-separated pre-release identifiers> ::= <pre-release identifier> > | <pre-release identifier> "." <dot-separated pre-release identifiers> > <pre-release identifier> ::= <alphanumeric identifier> > | <numeric identifier> > <numeric identifier> ::= "0" > | <positive digit> > | <positive digit> <digits> So this seems to mean “Numeric identifiers MAY be "0", but MUST NOT be any other number with leading zeroes" or something like that? Assuming that is the intention. It would be nice to clarify the natural-language statement in one shape or another, and if that is not the intended meaning, ajdust the examples and the BN grammar.
GiteaMirror added the question label 2026-06-15 12:01:48 -05:00
Author
Owner

@steveklabnik commented on GitHub (Jun 19, 2020):

It may be that it's early for me, but I don't see how these conflict? 0 is okay, but leading zeroes are not. maybe the ambiguity here is about what "leading" means? I've never heard "0" considered a "leading" zero before.

<!-- gh-comment-id:646707904 --> @steveklabnik commented on GitHub (Jun 19, 2020): It may be that it's early for me, but I don't see how these conflict? `0` is okay, but leading zeroes are not. maybe the ambiguity here is about what "leading" means? I've never heard "0" considered a "leading" zero before.
Author
Owner

@ljharb commented on GitHub (Jun 19, 2020):

+1, a leading zero is "0" followed by another digit; "0" is not a leading zero.

<!-- gh-comment-id:646720508 --> @ljharb commented on GitHub (Jun 19, 2020): +1, a leading zero is "0" followed by another digit; "0" is not a leading zero.
Author
Owner

@Anaphory commented on GitHub (Jun 19, 2020):

I'm not saying they conflict. I'm saying that there might be a phrase that makes it easier for the reader to not stumble over it and get the meaning across that a "0" not followed by any other digit is of course not a leading 0.

<!-- gh-comment-id:646807343 --> @Anaphory commented on GitHub (Jun 19, 2020): I'm not saying they conflict. I'm saying that there might be a phrase that makes it easier for the reader to not stumble over it and get the meaning across that a "0" not followed by any other digit is of course not a *leading* 0.
Author
Owner

@ljharb commented on GitHub (Jun 19, 2020):

I can't come up with any term that would better convey "there must be something after it" than "leading", since that's its literal definition, but i'm sure the maintainers would be happy to change it if a better suggestion materializes :-)

<!-- gh-comment-id:646843274 --> @ljharb commented on GitHub (Jun 19, 2020): I can't come up with any term that would better convey "there must be something after it" than "leading", since that's its literal definition, but i'm sure the maintainers would be happy to change it if a better suggestion materializes :-)
Author
Owner

@Vampire commented on GitHub (Jun 21, 2020):

I also agree that a standalone 0 is not a leading 0.
That is common terminology.
A leading 0 is a zero that is added as padding before another number, for example to make numbers equal in character lengths.

<!-- gh-comment-id:647191762 --> @Vampire commented on GitHub (Jun 21, 2020): I also agree that a standalone 0 is not a leading 0. That is common terminology. A leading 0 is a zero that is added as padding before another number, for example to make numbers equal in character lengths.
Author
Owner

@hinell commented on GitHub (Feb 12, 2022):

I'm afraid that BNF is broken.

Contrary to the spec quoted above the following grammar listed in the Semver 2.0 allows leading zeroes.:

...
<digits> ::= <digit>
           | <digit> <digits>

<digit> ::= "0"
          | <positive digit>
...

To fix that, I would suggest to list it a bit different way:

<digits> ::= <digit-zero>
          | <positive digit>
          | <positive digit> <digits>
<digit-zero> =: "0"

<!-- gh-comment-id:1037408652 --> @hinell commented on GitHub (Feb 12, 2022): I'm afraid that BNF is broken. Contrary to the spec quoted above the following grammar listed in the [Semver 2.0] allows leading zeroes.: ```EBNF ... <digits> ::= <digit> | <digit> <digits> <digit> ::= "0" | <positive digit> ... ``` To fix that, I would suggest to list it a bit different way: ```EBNF <digits> ::= <digit-zero> | <positive digit> | <positive digit> <digits> <digit-zero> =: "0" ``` [Semver 2.0]: https://semver.org/#backusnaur-form-grammar-for-valid-semver-versions
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/semver#5540