File tree 1 file changed +14
-2
lines changed
1 file changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,18 @@ import {
17
17
const cssCache = new Map < string , Promise < string > > ( )
18
18
const fontCache = new Map < string , any > ( )
19
19
20
+ // regexp is based on https://github.com/sindresorhus/escape-string-regexp
21
+ const reHasRegExp = / [ | \\ { } ( ) [ \] ^ $ + * ? . - ] /
22
+ const reReplaceRegExp = / [ | \\ { } ( ) [ \] ^ $ + * ? . - ] / g
23
+
24
+ function escapeStringRegexp ( str : string ) {
25
+ // see also: https://github.com/lodash/lodash/blob/2da024c3b4f9947a48517639de7560457cd4ec6c/escapeRegExp.js#L23
26
+ if ( reHasRegExp . test ( str ) ) {
27
+ return str . replace ( reReplaceRegExp , '\\$&' )
28
+ }
29
+ return str
30
+ }
31
+
20
32
const downloadGoogleFonts : FontLoader = async ( {
21
33
functionName,
22
34
data,
@@ -124,8 +136,8 @@ const downloadGoogleFonts: FontLoader = async ({
124
136
// Replace @font -face sources with self-hosted files
125
137
let updatedCssResponse = fontFaceDeclarations
126
138
for ( const { googleFontFileUrl, selfHostedFileUrl } of downloadedFiles ) {
127
- updatedCssResponse = updatedCssResponse . replaceAll (
128
- googleFontFileUrl ,
139
+ updatedCssResponse = updatedCssResponse . replace (
140
+ new RegExp ( escapeStringRegexp ( googleFontFileUrl ) , 'g' ) ,
129
141
selfHostedFileUrl
130
142
)
131
143
}
You can’t perform that action at this time.
0 commit comments