Skip to content

Commit

Permalink
fix unescaped ? and incorrectly escaped backreferences
Browse files Browse the repository at this point in the history
Refs #2
  • Loading branch information
brettflorio authored Feb 14, 2022
1 parent 35b72cd commit 0fc4136
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/Signer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,15 @@ export class Signer {
let pattern = new RegExp(
"<a .*?href=(['\"])(?<domain>[^'\"]*?)" +
this.cartPath +
"(.php)??(?<query>.*?)\\1[^>]*?>",
"(.php)?\?(?<query>.*?)\1[^>]*?>",
"gi"
);
return matchGroups(html, pattern);
}

private __getFormCodes(form: string): Product[] {
const regex = new RegExp(
"<[^>]*?name=(['\"])(?<prefix>[0-9]{1,3}:)?code\\1[^>]*?>",
"<[^>]*?name=(['\"])(?<prefix>[0-9]{1,3}:)?code\1[^>]*?>",
"ig"
);
const codes = matchGroups(form, regex);
Expand Down Expand Up @@ -178,7 +178,7 @@ export class Signer {
const pattern =
"(?<protocol>https?://)(?<domain>[^?/]*?)" +
this.cartPath +
"(.php)?\\?(?<querystring>.*)";
"(.php)?\?(?<querystring>.*)";
const match = url.match(pattern);
if (!match || !match.groups) {
return url;
Expand Down Expand Up @@ -356,7 +356,7 @@ export class Signer {
let pattern = new RegExp(
"<textarea [^>]*name=(['\"])" +
this.__prefixRegex(code.prefix) +
"(?![0-9]{1,3})(?<name>.+?)\\1[^>]*>(?<value>.*?)</textarea>",
"(?![0-9]{1,3})(?<name>.+?)\1[^>]*>(?<value>.*?)</textarea>",
"isg"
);
for (let textarea of matchGroups(html, pattern)) {
Expand Down Expand Up @@ -498,7 +498,7 @@ export class Signer {
const regex = new RegExp(
`href=(['"])${queryString.domain}${
this.cartPath
}(\.php)?.${queryString.query.replace(/^\?/, "")}\\1`
}(\.php)?.${queryString.query.replace(/^\?/, "")}\1`
);
if (signed != url) {
html = html.replace(regex, `href="${signed}"`);
Expand Down

0 comments on commit 0fc4136

Please sign in to comment.