Handle case where version regexp doesnt match

pull/17/merge
Felix Becker 2016-10-05 10:39:53 +02:00
parent 8cb1a8ea33
commit 1ac5a8fce3
1 changed files with 6 additions and 1 deletions

View File

@ -23,7 +23,12 @@ export function activate(context: vscode.ExtensionContext) {
} }
// Parse version and discard OS info like 7.0.8--0ubuntu0.16.04.2 // Parse version and discard OS info like 7.0.8--0ubuntu0.16.04.2
let version = stdout.toString().match(/^PHP ([^\s]+)/)[1].split('-')[0]; const match = stdout.toString().match(/^PHP ([^\s]+)/);
if (!match) {
vscode.window.showErrorMessage('Error parsing PHP version. Please check the output of php --version');
return;
}
let version = match[1].split('-')[0];
// Convert PHP prerelease format like 7.0.0rc1 to 7.0.0-rc1 // Convert PHP prerelease format like 7.0.0rc1 to 7.0.0-rc1
if (!/^\d+.\d+.\d+$/.test(version)) { if (!/^\d+.\d+.\d+$/.test(version)) {
version = version.replace(/(\d+.\d+.\d+)/, '$1-'); version = version.replace(/(\d+.\d+.\d+)/, '$1-');