♻️ Be more explicit in RegExp parsing
This commit is contained in:
parent
5caa3a935d
commit
0fc805f12d
3 changed files with 7 additions and 7 deletions
|
@ -37,7 +37,7 @@ const assert = (condition: boolean) => { if (!condition) { console.warn('Assert
|
|||
async function resolveDns(domain: string): Promise<IDnsResult[]> {
|
||||
return new Promise((resolve) => {
|
||||
//check given string for correctness to prevent injection attacks
|
||||
if (!domain.match(/^[a-z0-9]+([-.]{1}[a-z0-9]+)*\.[a-z]{2,3}$/)) { return resolve([]); }
|
||||
if (domain.match(/^[a-z0-9]+(?:[-.]{1}[a-z0-9]+)*\.[a-z]{2,3}$/) === null) { return resolve([]); }
|
||||
|
||||
//Check Level3/North_America separately
|
||||
if (domain !== 'cdn-patch.swtor.com') {
|
||||
|
|
|
@ -55,7 +55,7 @@ export default function verifyPatchmanifest(manifestFile: xmlJs.Element, product
|
|||
if (RequiredRelease.type !== 'element' || RequiredRelease.name !== 'RequiredRelease' || RequiredRelease.attributes !== undefined || RequiredRelease.elements === undefined) {
|
||||
throw new Error('Expected RequiredRelease element.');
|
||||
}
|
||||
if (RequiredRelease.elements.length !== 1 || RequiredRelease.elements[0].type !== 'text' || typeof RequiredRelease.elements[0].text !== 'string' || String(RequiredRelease.elements[0].text).match(/^(0|[1-9][0-9]*)$/) === null) {
|
||||
if (RequiredRelease.elements.length !== 1 || RequiredRelease.elements[0].type !== 'text' || typeof RequiredRelease.elements[0].text !== 'string' || String(RequiredRelease.elements[0].text).match(/^(?:0|[1-9][0-9]*)$/) === null) {
|
||||
throw new Error('Expected integer in RequiredRelease element.');
|
||||
}
|
||||
|
||||
|
@ -107,7 +107,7 @@ export default function verifyPatchmanifest(manifestFile: xmlJs.Element, product
|
|||
}
|
||||
//<Id>0</Id>
|
||||
const Id = Release.elements[0];
|
||||
if (Id.type !== 'element' || Id.name !== 'Id' || Id.attributes !== undefined || Id.elements === undefined || Id.elements.length !== 1 || Id.elements[0].type !== 'text' || typeof Id.elements[0].text !== 'string' || String(Id.elements[0].text).match(/^(0|[1-9][0-9]*)$/) === null) {
|
||||
if (Id.type !== 'element' || Id.name !== 'Id' || Id.attributes !== undefined || Id.elements === undefined || Id.elements.length !== 1 || Id.elements[0].type !== 'text' || typeof Id.elements[0].text !== 'string' || String(Id.elements[0].text).match(/^(?:0|[1-9][0-9]*)$/) === null) {
|
||||
throw new Error('Expected Id element.');
|
||||
}
|
||||
//<ReleaseName>53678f8057e52896a8145dca5c188ab3f24fa55f</SHA1>
|
||||
|
@ -138,7 +138,7 @@ export default function verifyPatchmanifest(manifestFile: xmlJs.Element, product
|
|||
throw new Error('Expected From element.');
|
||||
}
|
||||
const fromNum = From.elements[0].text;
|
||||
if (String(fromNum).match(/^(-1|0|[1-9][0-9]*)$/) === null) {
|
||||
if (String(fromNum).match(/^(?:-1|0|[1-9][0-9]*)$/) === null) {
|
||||
throw new Error(`Expected From element to be a number but it was ${fromNum}.`);
|
||||
}
|
||||
//<To>285</To>
|
||||
|
@ -147,7 +147,7 @@ export default function verifyPatchmanifest(manifestFile: xmlJs.Element, product
|
|||
throw new Error('Expected To element.');
|
||||
}
|
||||
const toNum = To.elements[0].text;
|
||||
if (String(toNum).match(/^(0|[1-9][0-9]*)$/) === null) {
|
||||
if (String(toNum).match(/^(?:0|[1-9][0-9]*)$/) === null) {
|
||||
throw new Error(`Expected To element to be a number but it was ${toNum}.`);
|
||||
}
|
||||
//TODO: check if From and To are valid relations
|
||||
|
@ -184,7 +184,7 @@ export default function verifyPatchmanifest(manifestFile: xmlJs.Element, product
|
|||
const valueName = String(Value.elements[0].text);
|
||||
switch (keyName) {
|
||||
case 'SSN_VERSION':
|
||||
if (!valueName.match(/^[0-9](\.[0-9])+$/)) {
|
||||
if (valueName.match(/^[0-9](?:\.[0-9])+$/) === null) {
|
||||
throw new Error(`Expected valid Value for Key "SSN_VERSION" in patch ${fromNum}to${toNum} but it was "${valueName}".`);
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -6,7 +6,7 @@ export default function verifySolidpkg(file: ISolid, { product, from, to }: {pro
|
|||
throw new Error(`Expected creation date to be a number but it was "${file['creation date']}".`);
|
||||
}
|
||||
//used by most .solidpkg files
|
||||
const announceGeneral = /^http:\/\/Tracker22\.[0-9a-z]{8}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{12}\.automated\.(tel\.swtor\.com|ssntracker\.int):80\/$/;
|
||||
const announceGeneral = /^http:\/\/Tracker22\.[0-9a-z]{8}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{12}\.automated\.(?:tel\.swtor\.com|ssntracker\.int):80\/$/;
|
||||
//used by retailclient_swtor_-1to0
|
||||
const announceRetailclientSwtor = /^http:\/\/Tracker14\.[0-9a-z]{8}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{12}\.automated\.snxd\.com:2500\/$/;
|
||||
if (file.announce.match(announceGeneral) === null && file.announce.match(announceRetailclientSwtor) === null) {
|
||||
|
|
Loading…
Reference in a new issue