diff --git a/cli/engine/engines/regex/detect-text.mjs b/cli/engine/engines/regex/detect-text.mjs
index 952ff78cf..26ca4f390 100644
--- a/cli/engine/engines/regex/detect-text.mjs
+++ b/cli/engine/engines/regex/detect-text.mjs
@@ -294,6 +294,7 @@ function blankHtmlAndCssCommentsOutsideScripts(text) {
function blankCssLineComments(text) {
let output = '';
let state = 'code';
+ let urlDepth = 0;
for (let i = 0; i < text.length; i++) {
const char = text[i];
const next = text[i + 1];
@@ -317,7 +318,7 @@ function blankCssLineComments(text) {
continue;
}
const prev = output.length ? output[output.length - 1] : '';
- if (char === '/' && next === '/' && prev !== ':' && prev !== '(' && prev !== '\\') {
+ if (char === '/' && next === '/' && urlDepth === 0 && prev !== ':' && prev !== '(' && prev !== '\\') {
output += ' ';
i++;
state = 'line';
@@ -325,6 +326,12 @@ function blankCssLineComments(text) {
}
if (char === "'") state = 'single';
else if (char === '"') state = 'double';
+ if (char === '(') {
+ const behind = output.replace(/\s+$/, '');
+ if (urlDepth > 0 || /url$/i.test(behind)) urlDepth++;
+ } else if (char === ')' && urlDepth) {
+ urlDepth--;
+ }
output += char;
}
return output;
@@ -367,6 +374,13 @@ function findAstroFrontmatterClose(text) {
cursor = commentEnd + 2;
continue;
}
+ if (char === '/' && next !== '/' && next !== '*') {
+ const close = findRegexLiteralEnd(text, cursor);
+ if (close !== -1) {
+ cursor = close + 1;
+ continue;
+ }
+ }
cursor++;
}
return -1;
diff --git a/tests/detect-antipatterns.test.js b/tests/detect-antipatterns.test.js
index 75fc7fe92..1f022b910 100644
--- a/tests/detect-antipatterns.test.js
+++ b/tests/detect-antipatterns.test.js
@@ -577,6 +577,33 @@ describe('detectText — broken images in source comments', () => {
expect(findings).toHaveLength(1);
expect(findings[0].line).toBe(3);
});
+
+ test('ignores frontmatter comments after a regex literal that contains quotes', () => {
+ const source = [
+ '---',
+ 'const re = /["\']/;',
+ '// ',
+ '---',
+ '