captureGroupsNeeded = version ? (version.match(/\\\d/g) || []).filter( function(value, index, self){
return self.indexOf(value) === index;
}).map( function(value){//Because Math.max needs the integers only
return parseInt(value.charAt(1), 10);//Will only work if backreferences cannot be any longer than a single digit
}) : [];
captureGroupsNeeded = version ? (version.match(/\\\d/g) || []).filter((value, index, self) => self.indexOf(value) === index).map(value => parseInt(value.charAt(1), 10), // Will only work if backreferences cannot be any longer than a single digit
if (amountOfCaptureGroups > amountOfCaptureGroupsNeeded) {
throw new Error('The pattern uses more capture groups than needed. Use non-capturing groups where appropriate.\n' + app + ': ' + type + ': ' + pattern);
throw new Error(`The pattern uses more capture groups than needed. Use non-capturing groups where appropriate.\n${app}: ${type}: ${pattern}`);
} else if (amountOfCaptureGroups < amountOfCaptureGroupsNeeded) {
throw new Error('The version string references more capture groups than there are in the pattern! Remove any incorrect back references from the version string and/or add the missing capture groups to the pattern.\n' + app + ': ' + type + ': ' + pattern);
throw new Error(`The version string references more capture groups than there are in the pattern! Remove any incorrect back references from the version string and/or add the missing capture groups to the pattern.\n${app}: ${type}: ${pattern}`);
} else if (highestBackReference > amountOfCaptureGroups) {
throw new Error('The version string references one or more capture groups whose index is higher than the amount of capture groups in the pattern. Please use the correct index instead of \\\\'+highestBackReference+'.\n' + app + ': ' + type + ': ' + pattern);
throw new Error(`The version string references one or more capture groups whose index is higher than the amount of capture groups in the pattern. Please use the correct index instead of \\\\${highestBackReference}.\n${app}: ${type}: ${pattern}`);
}
if (/^\/(?:\^\$|\.\+|\.\*)\/$/.test(regex)) {
throw new Error('Pattern should be replaced with empty string.\n' + app + ': ' + type + ': ' + pattern);
throw new Error(`Pattern should be replaced with empty string.\n${app}: ${type}: ${pattern}`);
}
if (type === 'html') {
if (/\.(?:\+|\*)/.test(regex)) {
throw new Error('Avoid ".+" and ".*" in HTML patterns. Consider using "[^>]+" or "[^<]+" instead.\n' + app + ': ' + type + ': ' + pattern);
throw new Error(`Avoid ".+" and ".*" in HTML patterns. Consider using "[^>]+" or "[^<]+" instead.\n${app}: ${type}: ${pattern}`);
}
if (!/[<>]/.test(regex)) {
throw new Error('HTML patterns must contain "<" or ">".\n' + app + ': ' + type + ': ' + pattern);
throw new Error(`HTML patterns must contain "<" or ">".\n${app}: ${type}: ${pattern}`);
}
}
@ -84,14 +79,13 @@ for ( app in json.apps ) {
// would mean not detecting the un-escaped ".". Replacing the character class with an
// underscore instead gives /test._+/, which WOULD yield a warning about the unescaped ".".)
if (/(?:^\/|[^\\])\.(?:[^*+]|\/$)/.test(regex.replace(/([^\\]|^)\[[^\]]+\]/g, '$1_'))) {
console.warn('Suspicious period (".") in pattern. Should this have been escaped?\n\tApp: ' + app + '\n\tPattern: ' + type + ': ' + pattern);
console.warn(`Suspicious period (".") in pattern. Should this have been escaped?\n\tApp: ${app}\n\tPattern: ${type}: ${pattern}`);
}
});
}
});
if (!/^https?:\/\//i.test(json.apps[app].website)) {