[GH-ISSUE #1021] Provided regexp matches <version core> "+" <build> "-" <pre-release> #4873

Closed
opened 2026-06-13 13:17:44 -05:00 by GiteaMirror · 3 comments
Owner

Originally created by @ykaliuta on GitHub (May 2, 2024).
Original GitHub issue: https://github.com/semver/semver/issues/1021

Looks like versions like 1.2.3+1-2 match the official regexp

/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/gm

but it is not part of the spec

<valid semver> ::= <version core>
                 | <version core> "-" <pre-release>
                 | <version core> "+" <build>
                 | <version core> "-" <pre-release> "+" <build>
Originally created by @ykaliuta on GitHub (May 2, 2024). Original GitHub issue: https://github.com/semver/semver/issues/1021 Looks like versions like ```1.2.3+1-2``` match the official regexp ``` /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/gm ``` but it is not part of the spec ``` <valid semver> ::= <version core> | <version core> "-" <pre-release> | <version core> "+" <build> | <version core> "-" <pre-release> "+" <build> ```
Author
Owner

@steveklabnik commented on GitHub (May 2, 2024):

This is the problem with trying to use a regex instead of a real parser. I imagine fixing this will be not particularly pretty.

<!-- gh-comment-id:2090957937 --> @steveklabnik commented on GitHub (May 2, 2024): This is the problem with trying to use a regex instead of a real parser. I imagine fixing this will be not particularly pretty.
Author
Owner

@zafarkhaja commented on GitHub (May 4, 2024):

but it is not part of the spec

It is part of the spec, you just need to go deeper into the <build> identifier.

<valid semver> ::= <version core> "+" <build>
<valid semver> ::= <version core> "+" <dot-separated build identifiers>
<valid semver> ::= <version core> "+" <build identifier>
<valid semver> ::= <version core> "+" <alphanumeric identifier>
<valid semver> ::= <version core> "+" <identifier characters> <non-digit> <identifier characters>
<valid semver> ::= <version core> "+" <identifier character> <non-digit> <identifier character>
<valid semver> ::= <version core> "+" <digit> <non-digit> <digit>
<valid semver> ::= <version core> "+" <digit> "-" <digit>
<!-- gh-comment-id:2094202671 --> @zafarkhaja commented on GitHub (May 4, 2024): > but it is not part of the spec It _is_ part of the spec, you just need to go deeper into the `<build>` identifier. <details> ```text <valid semver> ::= <version core> "+" <build> <valid semver> ::= <version core> "+" <dot-separated build identifiers> <valid semver> ::= <version core> "+" <build identifier> <valid semver> ::= <version core> "+" <alphanumeric identifier> <valid semver> ::= <version core> "+" <identifier characters> <non-digit> <identifier characters> <valid semver> ::= <version core> "+" <identifier character> <non-digit> <identifier character> <valid semver> ::= <version core> "+" <digit> <non-digit> <digit> <valid semver> ::= <version core> "+" <digit> "-" <digit> ``` </details>
Author
Owner

@ykaliuta commented on GitHub (May 6, 2024):

but it is not part of the spec

It is part of the spec, you just need to go deeper into the <build> identifier.

<valid semver> ::= <version core> "+" <build>
<valid semver> ::= <version core> "+" <dot-separated build identifiers>
<valid semver> ::= <version core> "+" <build identifier>
<valid semver> ::= <version core> "+" <alphanumeric identifier>
<valid semver> ::= <version core> "+" <identifier characters> <non-digit> <identifier characters>
<valid semver> ::= <version core> "+" <identifier character> <non-digit> <identifier character>
<valid semver> ::= <version core> "+" <digit> <non-digit> <digit>
<valid semver> ::= <version core> "+" <digit> "-" <digit>

True. Sorry for the noise

<!-- gh-comment-id:2096163383 --> @ykaliuta commented on GitHub (May 6, 2024): > > but it is not part of the spec > > It _is_ part of the spec, you just need to go deeper into the `<build>` identifier. > > ``` > <valid semver> ::= <version core> "+" <build> > <valid semver> ::= <version core> "+" <dot-separated build identifiers> > <valid semver> ::= <version core> "+" <build identifier> > <valid semver> ::= <version core> "+" <alphanumeric identifier> > <valid semver> ::= <version core> "+" <identifier characters> <non-digit> <identifier characters> > <valid semver> ::= <version core> "+" <identifier character> <non-digit> <identifier character> > <valid semver> ::= <version core> "+" <digit> <non-digit> <digit> > <valid semver> ::= <version core> "+" <digit> "-" <digit> > ``` True. Sorry for the noise
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/semver#4873