We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent ba3f4bb commit 49ee28fCopy full SHA for 49ee28f
frontend/scripts/gtmetrix-optimizer.cjs
@@ -316,7 +316,9 @@ function removeUnusedJavaScript() {
316
if (namedImports) {
317
const importNames = namedImports[1].split(',').map(name => name.trim());
318
const usedImports = importNames.filter(name => {
319
- const regex = new RegExp(`\\b${name}\\b`, 'g');
+ // Escape special regex characters to prevent invalid regex patterns
320
+ const escapedName = name.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
321
+ const regex = new RegExp(`\\b${escapedName}\\b`, 'g');
322
const matches = js.match(regex) || [];
323
return matches.length > 1; // More than just the import statement
324
});
0 commit comments