Skip to content

Commit cb65cb6

Browse files
Potential fix for code scanning alert no. 3: Incomplete string escaping or encoding
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent d9aca10 commit cb65cb6

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/parser/validator.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,10 @@ export class ReadmeValidator {
461461
});
462462

463463
// 3. Unmatched emphasis markers (simple heuristic)
464-
const countMatches = (text: string, token: string) => (text.match(new RegExp(token.replace(/([*~`])/g,'\\$1'),'g')) || []).length;
464+
function escapeRegExp(s: string): string {
465+
return s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
466+
}
467+
const countMatches = (text: string, token: string) => (text.match(new RegExp(escapeRegExp(token),'g')) || []).length;
465468
const totalDoubleAsterisk = countMatches(readme.rawContent, '**');
466469
if (totalDoubleAsterisk % 2 === 1) {
467470
warnings.push({

0 commit comments

Comments
 (0)