Skip to content

Commit

Permalink
Shorten methods
Browse files Browse the repository at this point in the history
  • Loading branch information
hansott committed Dec 18, 2024
1 parent 8b33e43 commit f1cd857
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions library/helpers/attackPath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ class Matches {
}
}

addMatch(path: PathPart[]) {
add(path: PathPart[]) {
this.matches.push(buildPathToPayload(path));
}

getMatches() {
return this.matches;
}

reachedMax() {
found() {
return this.matches.length >= this.max;
}
}
Expand All @@ -68,7 +68,7 @@ export function getPathsToPayload(
const attackPayloadLowercase = attackPayload.toLowerCase();

const traverse = (value: unknown, path: PathPart[] = [], depth = 0) => {
if (matches.reachedMax()) {
if (matches.found()) {
return;
}

Expand All @@ -78,7 +78,7 @@ export function getPathsToPayload(

if (typeof value === "string") {
if (value.toLowerCase() === attackPayloadLowercase) {
matches.addMatch(path);
matches.add(path);
return;
}

Expand All @@ -96,12 +96,12 @@ export function getPathsToPayload(
value.length < MAX_ARRAY_LENGTH &&
value.join().toLowerCase() === attackPayloadLowercase
) {
matches.addMatch(path);
matches.add(path);
return;
}

for (const [index, item] of value.entries()) {
if (matches.reachedMax() || index > MAX_ARRAY_LENGTH) {
if (matches.found() || index > MAX_ARRAY_LENGTH) {
break;
}

Expand All @@ -113,7 +113,7 @@ export function getPathsToPayload(

if (isPlainObject(value)) {
for (const key in value) {
if (matches.reachedMax()) {
if (matches.found()) {
break;
}

Expand Down

0 comments on commit f1cd857

Please sign in to comment.