Skip to content

Is 0000001.0000002.00300003 a valid semver or not? #112

Closed

Description

@isaacs

Came up in the discussions in #110.

Are leading zeroes allowed or not?

I think that they shouldn't be allowed, because it's strange to me that 0000001.0000002.00300003 would be functionally identical to 1.2.300003.

Same for numeric prerelease identifiers. Is 1.2.3-beta.000000000000009 the same as 1.2.3-beta.9 and 1.2.3-beta.09?

If leading zeros ARE allowed, then it should be made explicit. I'd assumed that they weren't allowed, and I doubt whether most SemVer parsers do allow them, at least in the main version.

In other words, I'm suggesting that the regular expression for major/minor/patch version segments would be something like /^[1-9]\d*|0$/.

Activity

  1. EddieGarmon commented on Jun 12, 2013

    @EddieGarmon
    Contributor

    Leading zeros SHOULD NOT be allowed for major, minor, patch.
    leading zeros SHOULD be allowed in prerelease and other metadata.

  2. petermichaux commented on Jun 12, 2013

    @petermichaux

    If leading zeros in the major, minor, and patch are allowed then I think the spec should say they have no meaning in comparing versions. If they have no meaning then they are not semantic and so allowing them is questionable in a standard called "semantic version"

    I think the most important part is clarity.

  3. tbull commented on Jun 12, 2013

    @tbull

    Is 0000001.0000002.00300003 a valid semver or not?

    According to the current spec, it's valid.

    Your example is a bit extreme. Albeit allowed, nobody would seriously go that far. A single leading zero in the minor part as in 1.09.2, however, could be seen as useful. I admit, use cases seem rather limited. Yet, any constraint should always be there for a good reason. I, personally, would not consider your example of possible abuse a good enough reason. But that's probably a matter of taste.

    Same for numeric prerelease identifiers. Is 1.2.3-beta.000000000000009 the same as 1.2.3-beta.9 and 1.2.3-beta.09?

    Again: yes. This has indeed led to the addition of some considerable amount of thought and code in my current implementation. I brought this up some time ago as an "implementation note" in #88.

    Leading zeros SHOULD NOT be allowed for major, minor, patch.
    leading zeros SHOULD be allowed in prerelease and other metadata.

    This is the worst option because it's inconsistent and thereby makes life for implementors even harder.

  4. isaacs commented on Jun 12, 2013

    @isaacs
    ContributorAuthor

    I agree with @tbull and @petermichaux that it should be clarified in the specification.

    However, we are in disagreement about whether leading zeroes should be allowed at all. There's no sense going back and forth re-making our cases, it's just bikeshedding at this point.

    Who's the person to make a decision on this definitively? @haacked? @mojombo? We need a dictatorial action :)

  5. petermichaux commented on Jun 12, 2013

    @petermichaux

    I believe that leading zeros should not be allowed in major, minor, and patch which is why I wrote the BNF the way I did in #110

  6. tbull commented on Jun 12, 2013

    @tbull

    Ok, let's wait for a dictator to show up... ;-)

  7. haacked commented on Jun 13, 2013

    @haacked
    Contributor

    I'm going to confer with @mojombo on this one, but my take is it shouldn't be allowed in Major.Minor.Patch.

    I tend to favor this:

    Leading zeros SHOULD NOT be allowed for major, minor, patch.
    leading zeros SHOULD be allowed in prerelease and other metadata.

    I know it's a bit inconsistent, but we've always had slightly different rules for pre-release identifiers than for Major, Minor, Patch so I'm not too concerned about that.

  8. domenic commented on Jun 13, 2013

    @domenic

    @haacked OK, so in that world, what's the answer to

    Is 1.2.3-beta.000000000000009 the same as 1.2.3-beta.9 and 1.2.3-beta.09?

    I'd guess beta numbers are lexical, so it's 1.2.3-beta.000000000000009 < 1.2.3-beta.09 < 1.2.3-beta.9 ?

  9. haacked commented on Jun 13, 2013

    @haacked
    Contributor

    I think we have to compare them as integers. Otherwise: 1.2.3-beta.09 < 1.2.3-beta.1 which goes against expectations. Right now, if a pre-release identifier only contains integers, we use integer comparison.

  10. domenic commented on Jun 13, 2013

    @domenic

    OK, so 1.2.3-beta.000000000000009 = 1.2.3-beta.09 = 1.2.3-beta.9?

  11. haacked commented on Jun 13, 2013

    @haacked
    Contributor

    BTW, I can see how that's a bit weird. Allowing leading 0s certainly keeps things simpler.

    Alternatively (and I throw this out for completeness), we could have pre-release identifiers be:

    ([1-9]\d*)|([a-zA-Z1-9-][a-zA-Z0-9-]*)

    In other words, if a pre-release identifier is only digits, it cannot have leading zeroes. Not sure I like that because it seems overly complicated.

    Also, it occurs to me that the spec allows - anywhere in a pre-release identifier, right? So 1.0.0-- is valid with the pre-release being -. ;)

  12. haacked commented on Jun 13, 2013

    @haacked
    Contributor

    @domenic that's what I think it should be, yes.

  13. domenic commented on Jun 13, 2013

    @domenic

    In other words, if a pre-release identifier is only digits, it cannot have leading zeroes. Not sure I like that because it seems overly complicated.

    This would be nicer IMO, not sure about how others in the thread feel. Mainly because having a canonical pre-release identifier seems better, instead of letting you prepend a 0 and get a new way of saying the same identifier.

  14. petermichaux commented on Jun 13, 2013

    @petermichaux

    ([1-9]\d*)|([a-zA-Z1-9-][a-zA-Z0-9-]*) does not allow patch like "-alpha.0.1.0" where some are just zero. It also doesn't allow "-alpha.0foo".

  15. haacked commented on Jun 13, 2013

    @haacked
    Contributor

    @petermichaux nice catch. My regex fu is weak sauce today. How's this?

    (0)|([1-9]\d*)|([a-zA-Z1-9-][a-zA-Z0-9-]*)
    
  16. isaacs commented on Jun 13, 2013

    @isaacs
    ContributorAuthor

    No need for the triple-capture. If you have a system (such as JavaScript) supporting negative lookahead, you can do it this way, which is closer to the "spirit" of what the spec would say: /(?!^0\d+$)(^[a-zA-Z0-9-]+$)/. In other words, "Any combination of letters, numbers, and hyphens, except a purely numeric identifier containing leading zeroes."

    > r = /(?!^0\d+$)(^[a-zA-Z0-9-]+$)/
    /(?!^0\d+$)(^[a-zA-Z0-9-]+$)/
    > r.test('0')
    true
    > r.test('asdf0foo')
    true
    > r.test('a-b-c')
    true
    > r.test('100')
    true
    > r.test('0100')
    false
    
  17. mojombo commented on Jun 13, 2013

    @mojombo
    Contributor

    Leading zeros seem like YAGNI to me and only serve to open up confusing comparisons and precedence mistakes. The spec is already quite restrictive on what is valid so forbidding leading zeros doesn't strike me as inconsistent and nicely renders all of these nuanced decisions moot.

    Part of my vision for SemVer is to prevent people from having to think about stuff that doesn't matter, and contemplating how leading zeros affect precedence is something that doesn't matter.

  18. isaacs commented on Jun 13, 2013

    @isaacs
    ContributorAuthor

    @mojombo So the decision is "no leading zeroes" then? +01 to that ;)

  19. mojombo commented on Jun 13, 2013

    @mojombo
    Contributor

    Oh, another reason to forbid leading zeros is because it then allows two valid (non-build) versions to have identical precedence which means more undefined behavior in tools that care about this stuff.

  20. added a commit that references this issue on Jun 14, 2013
    9248bf1
  21. haacked commented on Jun 14, 2013

    @haacked
    Contributor

    @mojombo What about for pre-release identifiers? Based on what you said, we should probably not allow leading 0s for pre-release identifiers that only contain digits, right?

    1.0.0-alpha.001 vs 1.0.0-alpha.1?

  22. mojombo commented on Jun 15, 2013

    @mojombo
    Contributor

    @haacked Correct. 1.0.0-alpha.001 would not be valid.

  23. added a commit that references this issue on Jul 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions