1
0
mirror of https://github.com/nvm-sh/nvm.git synced 2026-10-25 15:55:46 +08:00
Files
nvm/test
Jordan Harband 09822033d2 [Fix] nvm exec/nvm run: do not treat filenames with digits as versions
`nvm_is_valid_version` accepted strings like `123.js`, `v1.js`, and `1.2.3.4.5.6.js`, because `nvm_version_greater_than_or_equal_to` exits as soon as the first number is greater than zero, without looking at the rest.
So `nvm run 123.js` failed with `N/A: version "v123.js" is not yet installed` instead of running the file.

It now checks the shape first: one to three dot-separated numbers, optionally with a trailing dot, and a prerelease suffix (rc, nightly, v8-canary, test builds) only after a full `x.y.z`.
A suffix with a dot followed by a non-digit, like a file extension, is rejected, so names like `1.2.3-foo.js` are treated as files too.
Every version listed in the nodejs.org and iojs.org `index.tab` files is still accepted, so shell startup keeps using a `default` alias that resolves to an installed prerelease.

Names that are also valid versions, like `123` or `v1`, are still treated as versions; `nvm run current 123` runs such a file.

Refs #1166. See #3931.
2026-09-28 15:05:28 +09:00
..