in src/utils/nugetUtils.ts [55:148]
function parseVersionRange(value: string): IVersionRange | string {
const error: Error = new Error(localize('invalidRange', 'Invalid range "{0}"', value));
value = value.trim();
// * is the only range below 3 chars
if (value === wildcard) {
return value;
}
// Fail early if the string is too short to be valid
if (value.length < 3) {
throw error;
}
let includeMinVersion: boolean;
let minVersion: string | undefined;
let includeMaxVersion: boolean | undefined;
let maxVersion: string | undefined;
if (value[0] === '(' || value[0] === '[') {
// The first character must be [ or (
switch (value[0]) {
case '[':
includeMinVersion = true;
break;
case '(':
includeMinVersion = false;
break;
default:
throw error;
}
// The last character must be ] or )
switch (value[value.length - 1]) {
case ']':
includeMaxVersion = true;
break;
case ')':
includeMaxVersion = false;
break;
default:
throw error;
}
// Get rid of the two brackets
value = value.substring(1, value.length - 1);
// Split by comma, and make sure we get between 1 and 2 non-empty parts
const parts: string[] = value.split(',').map(p => p.trim());
if (parts.length > 2 || !parts.some(p => !!p)) {
throw error;
}
// If there is only one part, use it for both min and max
minVersion = parts[0];
maxVersion = parts.length === 2 ? parts[1] : parts[0];
} else {
if (value.includes(wildcard)) { // If the value has wildcards, it denotes a range
return value;
} else { // Otherwise, it denotes the minimum version (inclusive)
includeMinVersion = true;
minVersion = value;
}
}
if (minVersion) {
if (minVersion.includes(wildcard)) {
if (!semver.validRange(minVersion)) {
throw error;
}
} else {
minVersion = appendMissingParts(minVersion);
if (!semver.valid(minVersion)) {
throw error;
}
}
}
if (maxVersion) {
// max does not support wildcards
maxVersion = appendMissingParts(maxVersion);
if (!semver.valid(maxVersion)) {
throw error;
}
}
return {
minVersion,
includeMinVersion,
maxVersion,
includeMaxVersion
};
}