-
Notifications
You must be signed in to change notification settings - Fork 21
Potential fix for code scanning alert no. 71: Incomplete string escaping or encoding #1376
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
3f4c928
020c230
6bd27a9
01a64b8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -112,9 +112,14 @@ export function findMetadataPhaseMatch( | |
| return { source: 'stringExact' } | ||
| } | ||
|
|
||
| const escapedTarget = escapeRegexLiteral(target) | ||
| .replace(/ /g, '\\ ') | ||
| const sepInsensitive = new RegExp(`\\b${escapedTarget.replace(/\\ /g, '[-_\\s]+')}\\b`) | ||
| // Replace all sequences of space, underscore, or hyphen in the target with a placeholder | ||
| const WORDSEP_PLACEHOLDER = '__WORDSEP__' | ||
| const sepPattern = /[ \-_]+/g | ||
| const targetWithPlaceholder = target.replace(sepPattern, WORDSEP_PLACEHOLDER) | ||
| // Properly escape ALL regex metacharacters (including backslash), leaving the placeholder intact | ||
| const escapedTarget = escapeRegexLiteral(targetWithPlaceholder) | ||
| .replace(new RegExp(escapeRegexLiteral(WORDSEP_PLACEHOLDER), 'g'), '[-_\\s]+') | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [ |
||
| const sepInsensitive = new RegExp(`\\b${escapedTarget}\\b`) | ||
| if (sepInsensitive.test(normalizedMetadata)) { | ||
| return { source: 'stringBoundary' } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[💡
style]Consider adding semicolons at the end of statements to maintain consistency with the rest of the codebase, which uses semicolons. This can help prevent potential issues with automatic semicolon insertion.