From e7d1537c378b83b8049f65dda471d87a2f7b2df2 Mon Sep 17 00:00:00 2001 From: Kurt Date: Fri, 5 Dec 2025 09:29:15 +1100 Subject: [PATCH] Use named capture groups for version string matching Previously it was referencing the wrong group index (off by one), which is easy to do when relying on indices. Using capture groups here should make it less error prone (and also fixes this initial problem). Long term a small unit test should avoid this happening / regressing. --- common.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/common.js b/common.js index f0e11da..07d1b88 100644 --- a/common.js +++ b/common.js @@ -179,13 +179,13 @@ function versionLessThan(cur_ver, min_ver) { // 'dev' is `null` if `str` was not a dev version. // On failure, returns `null`. function parseVersion(str) { - const match = /^(\d+)\.(\d+)\.(\d+)(?:-dev\.(\d+)\+[0-9a-f]*)?$/.exec(str); + const match = /^(?\d+)\.(?\d+)\.(?\d+)(?:-dev\.(?\d+)\+[0-9a-f]*)?$/.exec(str); if (match === null) return null; return { - major: parseInt(match[0]), - minor: parseInt(match[1]), - patch: parseInt(match[2]), - dev: match[3] === null ? null : parseInt(match[3]), + major: parseInt(match.groups['major']), + minor: parseInt(match.groups['minor']), + patch: parseInt(match.groups['patch']), + dev: match.groups['dev'] === undefined ? null : parseInt(match.groups['dev']), }; }