Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Coercing version with prerelease identifier that starts with digits returns truncated identifier #775

Open
1 task done
nhedger opened this issue Mar 26, 2025 · 0 comments
Labels
Bug thing that needs fixing Needs Triage needs an initial review

Comments

@nhedger
Copy link

nhedger commented Mar 26, 2025

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

Using semver 7.7.1 (and possibly earlier versions), attempting to coerce a version string that contains a prerelease identifier that starts with digits, will result in that identifier to be truncated after the digits.

Here are some example:

  • 1.0.0-alpha.1ab produces 1.0.0-alpha.1
  • 1.0.0-alpha.12ab produces 1.0.0-alpha.12
  • 1.0.0-alpha.1234.23cd produces 1.0.0-alpha.1234.23

This is problematic when the identifier is a hash that may start with a digit.

The issue doesn't seem to happen if the identifier is composed of only number, or if the identifier starts with an alphabetic character:

  • 1.9.5-nightly.abc123 is coerced as expected
  • 1.9.5-nightly.abcdef is coerced as expected
  • 1.9.5-nightly.123456 is coerced as expected

Expected Behavior

The prerelease identifier isn't truncated.

Steps To Reproduce

  1. Clone the reproduction repository: https://github.com/nhedger/semver-prerelease-issue
  2. Install the dependencies
  3. Run node index.mjs
  4. See that the prerelease identifier is truncated

Environment

  • npm: 10.8.2
  • Node: 20.17.0
  • OS: macOS
  • platform: MacBook Pro M1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing Needs Triage needs an initial review
Projects
None yet
Development

No branches or pull requests

1 participant