MCPcopy Create free account
hub / github.com/codeaashu/claude-code / hasWildcards

Function hasWildcards

src/utils/permissions/shellRuleMatching.ts:54–78  ·  view source on GitHub ↗
(pattern: string)

Source from the content-addressed store, hash-verified

52 * Returns true if the pattern contains * that are not escaped with \ or part of :* at the end.
53 */
54export function hasWildcards(pattern: string): boolean {
55 // If it ends with :*, it's legacy prefix syntax, not wildcard
56 if (pattern.endsWith(':*')) {
57 return false
58 }
59 // Check for unescaped * anywhere in the pattern
60 // An asterisk is unescaped if it's not preceded by a backslash,
61 // or if it's preceded by an even number of backslashes (escaped backslashes)
62 for (let i = 0; i < pattern.length; i++) {
63 if (pattern[i] === '*') {
64 // Count backslashes before this asterisk
65 let backslashCount = 0
66 let j = i - 1
67 while (j >= 0 && pattern[j] === '\\') {
68 backslashCount++
69 j--
70 }
71 // If even number of backslashes (including 0), the asterisk is unescaped
72 if (backslashCount % 2 === 0) {
73 return true
74 }
75 }
76 }
77 return false
78}
79
80/**
81 * Match a command against a wildcard pattern.

Callers 1

parsePermissionRuleFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected