Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 23 additions & 5 deletions src/detect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,29 @@ export const extractVersionFromOutput = (output: string): string => {
return '';
}

// Extract version number using semver pattern
// Matches: major.minor.patch[-prerelease][+build] but only captures up to prerelease
const semverRegex = /v?(\d+\.\d+\.\d+(?:-[a-zA-Z0-9.-]+)?)(?:\+[a-zA-Z0-9.-]+)?/;
const match = output.match(semverRegex);
return match ? match[1] : '';
// Split into lines and look for version information on dedicated lines
// This avoids extracting versions from file paths like /opt/homebrew/Cellar/dev-proxy/v0.29.1/devproxy-errors.json
const lines = output.split('\n');

// Look for lines that contain version information (not file paths)
for (const line of lines) {
const trimmedLine = line.trim();

// Skip lines that contain file paths (indicated by slashes and common path patterns)
if (trimmedLine.includes('/') || trimmedLine.includes('\\') || trimmedLine.includes('loaded from')) {
continue;
}

// Look for version pattern on non-filepath lines
// Matches: major.minor.patch[-prerelease][+build] but only captures up to prerelease
const semverRegex = /v?(\d+\.\d+\.\d+(?:-[a-zA-Z0-9.-]+)?)(?:\+[a-zA-Z0-9.-]+)?/;
const match = trimmedLine.match(semverRegex);
if (match) {
return match[1];
}
}

return '';
};

export const getOutdatedVersion = async (devProxyExe: string): Promise<string> => {
Expand Down
60 changes: 60 additions & 0 deletions src/test/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -625,4 +625,64 @@ suite('extractVersionFromOutput', () => {
const result = detect.extractVersionFromOutput(output);
assert.strictEqual(result, '1.0.0-beta.1');
});

test('should not extract version from file paths in error responses (issue #286)', () => {
const output = `info 1 error responses loaded from /opt/homebrew/Cellar/dev-proxy/v0.29.1/devproxy-errors.json`;

const result = detect.extractVersionFromOutput(output);
assert.strictEqual(result, '');
});

test('should extract version from update notification line, ignoring file paths (issue #286)', () => {
const output = `info 1 error responses loaded from /opt/homebrew/Cellar/dev-proxy/v0.29.0/devproxy-errors.json
info v0.29.1`;

const result = detect.extractVersionFromOutput(output);
assert.strictEqual(result, '0.29.1');
});

test('should not extract version from Windows file paths', () => {
const output = `info 1 error responses loaded from C:\\Program Files\\dev-proxy\\v0.29.1\\devproxy-errors.json`;

const result = detect.extractVersionFromOutput(output);
assert.strictEqual(result, '');
});

test('should extract version from actual update notification with Windows paths in earlier lines', () => {
const output = `info 1 error responses loaded from C:\\Program Files\\dev-proxy\\v0.29.0\\devproxy-errors.json
info v0.29.1`;

const result = detect.extractVersionFromOutput(output);
assert.strictEqual(result, '0.29.1');
});

test('should not extract beta version from Unix file paths (issue #286)', () => {
const output = `info 1 error responses loaded from /opt/homebrew/Cellar/dev-proxy/v0.30.0-beta.2/devproxy-errors.json`;

const result = detect.extractVersionFromOutput(output);
assert.strictEqual(result, '');
});

test('should not extract beta version from Windows file paths (issue #286)', () => {
const output = `info 1 error responses loaded from C:\\Program Files\\dev-proxy\\v0.30.0-beta.2\\devproxy-errors.json`;

const result = detect.extractVersionFromOutput(output);
assert.strictEqual(result, '');
});

test('should extract beta version from update notification, ignoring file paths (issue #286)', () => {
const output = `info 1 error responses loaded from /opt/homebrew/Cellar/dev-proxy/v0.30.0-beta.1/devproxy-errors.json
info v0.30.0-beta.2`;

const result = detect.extractVersionFromOutput(output);
assert.strictEqual(result, '0.30.0-beta.2');
});

test('should extract beta version from update notification with Windows paths in earlier lines (issue #286)', () => {
const output = `info 1 error responses loaded from C:\\Program Files\\dev-proxy\\v0.30.0-beta.1\\devproxy-errors.json
info v0.30.0-beta.2`;

const result = detect.extractVersionFromOutput(output);
assert.strictEqual(result, '0.30.0-beta.2');
});
});