| 42 | // Prevents `~/Desktop/YT` from matching `~/Desktop/YT_archive`, while still matching |
| 43 | // `~/Desktop/YT`, `~/Desktop/YT/foo`, `~/Desktop/YT"`, `~/Desktop/YT ` (space = boundary). |
| 44 | function commandReferencesPath(command: string, protectedPath: string): boolean { |
| 45 | if (!protectedPath) return false; |
| 46 | let idx = command.indexOf(protectedPath); |
| 47 | while (idx >= 0) { |
| 48 | const after = command[idx + protectedPath.length]; |
| 49 | if (!after || !/[A-Za-z0-9_-]/.test(after)) return true; |
| 50 | idx = command.indexOf(protectedPath, idx + 1); |
| 51 | } |
| 52 | return false; |
| 53 | } |
| 54 | |
| 55 | function isPathMatch(targetPath: string, pattern: string, cwd: string): boolean { |
| 56 | // Simple glob-to-regex or substring match |