Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/apps/review/src/lib/utils/metadataMatching.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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__'

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.

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]+')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[⚠️ correctness]
The replacement pattern [-_\s]+ is used to match sequences of separators. Ensure that this pattern aligns with the intended behavior and that no additional separators need to be considered. If the pattern should be more flexible, consider documenting the expected input format.

const sepInsensitive = new RegExp(`\\b${escapedTarget}\\b`)
if (sepInsensitive.test(normalizedMetadata)) {
return { source: 'stringBoundary' }
}
Expand Down
Loading