MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / matchesPattern

Function matchesPattern

source code/utils/hooks.ts:1348–1383  ·  view source on GitHub ↗

* Check if a match query matches a hook matcher pattern * @param matchQuery The query to match (e.g., 'Write', 'Edit', 'Bash') * @param matcher The matcher pattern - can be: * - Simple string for exact match (e.g., 'Write') * - Pipe-separated list for multiple exact matches (e.g., 'Write|Edi

(matchQuery: string, matcher: string)

Source from the content-addressed store, hash-verified

1346 * @returns true if the query matches the pattern
1347 */
1348function matchesPattern(matchQuery: string, matcher: string): boolean {
1349 if (!matcher || matcher === '*') {
1350 return true
1351 }
1352 // Check if it's a simple string or pipe-separated list (no regex special chars except |)
1353 if (/^[a-zA-Z0-9_|]+$/.test(matcher)) {
1354 // Handle pipe-separated exact matches
1355 if (matcher.includes('|')) {
1356 const patterns = matcher
1357 .split('|')
1358 .map(p => normalizeLegacyToolName(p.trim()))
1359 return patterns.includes(matchQuery)
1360 }
1361 // Simple exact match
1362 return matchQuery === normalizeLegacyToolName(matcher)
1363 }
1364
1365 // Otherwise treat as regex
1366 try {
1367 const regex = new RegExp(matcher)
1368 if (regex.test(matchQuery)) {
1369 return true
1370 }
1371 // Also test against legacy names so patterns like "^Task$" still match
1372 for (const legacyName of getLegacyToolNames(matchQuery)) {
1373 if (regex.test(legacyName)) {
1374 return true
1375 }
1376 }
1377 return false
1378 } catch {
1379 // If the regex is invalid, log error and return false
1380 logForDebugging(`Invalid regex pattern in hook matcher: ${matcher}`)
1381 return false
1382 }
1383}
1384
1385type IfConditionMatcher = (ifCondition: string) => boolean
1386

Callers 1

getMatchingHooksFunction · 0.85

Calls 3

normalizeLegacyToolNameFunction · 0.85
getLegacyToolNamesFunction · 0.85
logForDebuggingFunction · 0.85

Tested by

no test coverage detected