Skip to content

Commit 92a3962

Browse files
authored
Merge pull request #1376 from topcoder-platform/alert-autofix-71
Potential fix for code scanning alert no. 71: Incomplete string escaping or encoding
2 parents 9ed7544 + 01a64b8 commit 92a3962

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/apps/review/src/lib/utils/metadataMatching.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,14 @@ export function findMetadataPhaseMatch(
112112
return { source: 'stringExact' }
113113
}
114114

115-
const escapedTarget = escapeRegexLiteral(target)
116-
.replace(/ /g, '\\ ')
117-
const sepInsensitive = new RegExp(`\\b${escapedTarget.replace(/\\ /g, '[-_\\s]+')}\\b`)
115+
// Replace all sequences of space, underscore, or hyphen in the target with a placeholder
116+
const WORDSEP_PLACEHOLDER = '__WORDSEP__'
117+
const sepPattern = /[ \-_]+/g
118+
const targetWithPlaceholder = target.replace(sepPattern, WORDSEP_PLACEHOLDER)
119+
// Properly escape ALL regex metacharacters (including backslash), leaving the placeholder intact
120+
const escapedTarget = escapeRegexLiteral(targetWithPlaceholder)
121+
.replace(new RegExp(escapeRegexLiteral(WORDSEP_PLACEHOLDER), 'g'), '[-_\\s]+')
122+
const sepInsensitive = new RegExp(`\\b${escapedTarget}\\b`)
118123
if (sepInsensitive.test(normalizedMetadata)) {
119124
return { source: 'stringBoundary' }
120125
}

0 commit comments

Comments
 (0)