Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
chrmod committed Nov 9, 2023
1 parent 0d7eee6 commit d33930c
Showing 1 changed file with 3 additions and 16 deletions.
19 changes: 3 additions & 16 deletions packages/adblocker/src/filters/cosmetic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,6 @@ function isSimpleHrefSelector(selector: string, start: number): boolean {
);
}

// source https://stackoverflow.com/a/1144788
function escapeRegExp(string: string): string {
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
}

function replaceAll(str: string, find: string, replace: string): string {
return str.replace(new RegExp(escapeRegExp(find), 'g'), replace);
}

/**
* Validate CSS selector. There is a fast path for simple selectors (e.g.: #foo
* or .bar) which are the most common case. For complex ones, we rely on
Expand Down Expand Up @@ -769,13 +760,9 @@ export default class CosmeticFilter implements IFilter {
return part;
})
.map((part: string) => {
const withoutUnicodeCommas = replaceAll(part, String.raw`\u002C`, ',');
const withoutUnicodeBackslashed = replaceAll(
withoutUnicodeCommas,
String.raw`\u005C`,
'\\',
);
return withoutUnicodeBackslashed;
return part
.replace(new RegExp(String.raw`\u002C`, 'g'), ',')
.replace(new RegExp(String.raw`\u005C`, 'g'), '\\');
});
return { name: parts[0], args };
}
Expand Down

0 comments on commit d33930c

Please sign in to comment.