Skip to content

Commit 5655ba1

Browse files
Copilotdata-douser
andcommitted
refactor: improve parseVersionString to use last version match on first line
Agent-Logs-Url: https://github.com/advanced-security/codeql-development-mcp-server/sessions/c79f4c66-0204-436a-85bb-014f590878a1 Co-authored-by: data-douser <70299490+data-douser@users.noreply.github.com>
1 parent 78e0e55 commit 5655ba1

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

extensions/vscode/src/codeql/cli-resolver.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,16 @@ export class CliResolver extends DisposableObject {
127127
* - "CodeQL command-line toolchain release 2.19.0."
128128
* - "CodeQL CLI 2.25.1"
129129
*
130+
* The regex looks for the last `X.Y.Z` triplet on the first line,
131+
* which avoids matching unrelated version numbers that may appear
132+
* earlier in error messages.
133+
*
130134
* Returns the bare version (e.g. '2.25.1') or `undefined` if not parseable.
131135
*/
132136
static parseVersionString(versionOutput: string): string | undefined {
133-
const match = /(\d+\.\d+\.\d+)/.exec(versionOutput);
134-
return match?.[1];
137+
const firstLine = versionOutput.split('\n')[0] ?? '';
138+
const matches = [...firstLine.matchAll(/(\d+\.\d+\.\d+)/g)];
139+
return matches.length > 0 ? matches[matches.length - 1][1] : undefined;
135140
}
136141

137142
/**

0 commit comments

Comments
 (0)