Skip to content

fix: use greedy regex for version parsing#147

Open
ss251 wants to merge 2 commits intosolana-foundation:masterfrom
ss251:fix/version-regex-non-greedy
Open

fix: use greedy regex for version parsing#147
ss251 wants to merge 2 commits intosolana-foundation:masterfrom
ss251:fix/version-regex-non-greedy

Conversation

@ss251
Copy link
Copy Markdown

@ss251 ss251 commented Jan 18, 2026

Problem

The VERSION_REGEX in src/lib/shell/index.ts uses a non-greedy quantifier (\d+?) for the patch version, causing versions like 0.4.11 to be incorrectly parsed as 0.4.1. This results in false "update available" warnings when tools are already at the latest version.

Example:

ℹ solana-verify 0.4.1 is already installed - v0.4.11 available

When solana-verify --version actually returns 0.4.11.

Summary of Changes

Changed from non-greedy to greedy quantifier in VERSION_REGEX:

- export const VERSION_REGEX = /(?:[\w-]+\s+)?(\d+\.\d+\.?\d+?)/;
+ export const VERSION_REGEX = /(?:[\w-]+\s+)?(\d+\.\d+\.?\d+)/;

Test:

// Before (buggy)
/(?:[\w-]+\s+)?(\d+\.\d+\.?\d+?)/.exec('solana-verify 0.4.11')[1]
// => '0.4.1'

// After (fixed)
/(?:[\w-]+\s+)?(\d+\.\d+\.?\d+)/.exec('solana-verify 0.4.11')[1]
// => '0.4.11'

Related PR

See also #150 which fixes a separate issue where the "update available" warning shows even when needsUpdate is false. Both PRs together fully resolve the false warning issue:

Fixes #148

The VERSION_REGEX used a non-greedy quantifier (\d+?) for the patch
version, causing versions like "0.4.11" to be incorrectly parsed as
"0.4.1". This resulted in false "update available" warnings when
tools were already at the latest version.

Changed from: /(?:[\w-]+\s+)?(\d+\.\d+\.?\d+?)/
Changed to:   /(?:[\w-]+\s+)?(\d+\.\d+\.?\d+)/
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Jan 18, 2026

🦋 Changeset detected

Latest commit: 2cf73b9

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
mucho Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

VERSION_REGEX incorrectly parses versions with multi-digit patch numbers

1 participant