Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
dumbmatter committed Feb 2, 2025
1 parent 217b028 commit 6cdd563
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/common/polyfills.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ import "./polyfill-TextEncoderDecoderStream";

// Chrome 85, Safari 13.1
if (!String.prototype.replaceAll) {
const escapeRegex = (string: string) => {
// eslint-disable-next-line unicorn/prefer-string-replace-all
return string.replace(/[$()*+./?[\\\]^{|}-]/g, String.raw`\$&`);
};

(String as any).prototype.replaceAll = function (
str: string | RegExp,
newStr: string,
Expand All @@ -138,7 +143,7 @@ if (!String.prototype.replaceAll) {

// If a string
// eslint-disable-next-line unicorn/prefer-string-replace-all
return this.replace(new RegExp(str, "g"), newStr);
return this.replace(new RegExp(escapeRegex(str as string), "g"), newStr);
};
}

Expand Down

0 comments on commit 6cdd563

Please sign in to comment.