Skip to content

Commit

Permalink
fix regex
Browse files Browse the repository at this point in the history
  • Loading branch information
jribbink committed Jan 12, 2024
1 parent a519012 commit 33b8579
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions extension/src/utils/flow-version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ export function extractFlowCLIVersion (buffer: Buffer | string): string | null {
const output = buffer.toString()

const versionRegex = /Version: v((0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?)/g
let versionMatch = output.match(versionRegex)
let versionMatch = versionRegex.exec(output)

if (versionMatch != null) return versionMatch[1]

// Fallback regex to semver if versionRegex fails (protect against future changes to flow version output)
const fallbackRegex = /(((0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*)))?)/g
versionMatch ??= output.match(fallbackRegex)
versionMatch ??= fallbackRegex.exec(output)
if (versionMatch != null) {
void vscode.window.showWarningMessage(`Unfamiliar Flow CLI version format. Assuming that version is ${versionMatch[1]}. Please report this issue to the Flow team.`)
return versionMatch[1]
Expand Down
2 changes: 1 addition & 1 deletion extension/test/unit/parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ASSERT_EQUAL } from '../globals'

suite('Parsing Unit Tests', () => {
test('Flow CLI Version Extraction', async () => {
let versionTest: Buffer = Buffer.from('Version: v0.1.0\nCommit: 0a1b2c3d')
let versionTest: Buffer = Buffer.from('Foobar123\nVersion: v0.1.0\nCommit: 0a1b2c3d')
let formatted = extractFlowCLIVersion(versionTest)
ASSERT_EQUAL(formatted, 'v0.1.0')

Expand Down

0 comments on commit 33b8579

Please sign in to comment.