(cmd: {
name: string
args: string[]
})
| 80 | * and colon-bound values (`-it:Junction`). |
| 81 | */ |
| 82 | export function isSymlinkCreatingCommand(cmd: { |
| 83 | name: string |
| 84 | args: string[] |
| 85 | }): boolean { |
| 86 | const canonical = resolveToCanonical(cmd.name) |
| 87 | if (canonical !== 'new-item') return false |
| 88 | for (let i = 0; i < cmd.args.length; i++) { |
| 89 | const raw = cmd.args[i] ?? '' |
| 90 | if (raw.length === 0) continue |
| 91 | // Normalize unicode dash prefixes (–, —, ―) and forward-slash (PS 5.1 |
| 92 | // parameter prefix) → ASCII `-` so prefix comparison works. PS tokenizer |
| 93 | // treats all four dash chars plus `/` as parameter markers. (bug #26) |
| 94 | const normalized = |
| 95 | PS_TOKENIZER_DASH_CHARS.has(raw[0]!) || raw[0] === '/' |
| 96 | ? '-' + raw.slice(1) |
| 97 | : raw |
| 98 | const lower = normalized.toLowerCase() |
| 99 | // Split colon-bound value: -it:SymbolicLink → param='-it', val='symboliclink' |
| 100 | const colonIdx = lower.indexOf(':', 1) |
| 101 | const paramRaw = colonIdx > 0 ? lower.slice(0, colonIdx) : lower |
| 102 | // Strip backtick escapes: -Item`Type → -ItemType (bug #22) |
| 103 | const param = paramRaw.replace(/`/g, '') |
| 104 | if (!isItemTypeParamAbbrev(param)) continue |
| 105 | const rawVal = |
| 106 | colonIdx > 0 |
| 107 | ? lower.slice(colonIdx + 1) |
| 108 | : (cmd.args[i + 1]?.toLowerCase() ?? '') |
| 109 | // Strip backtick escapes from colon-bound value: -it:Sym`bolicLink → symboliclink |
| 110 | // Mirrors the param-name strip at L103. Space-separated args use .value |
| 111 | // (backtick-resolved by .NET parser), but colon-bound uses .text (raw source). |
| 112 | // Strip surrounding quotes: -it:'SymbolicLink' or -it:"Junction" (bug #6) |
| 113 | const val = rawVal.replace(/`/g, '').replace(/^['"]|['"]$/g, '') |
| 114 | if (LINK_ITEM_TYPES.has(val)) return true |
| 115 | } |
| 116 | return false |
| 117 | } |
| 118 | |
| 119 | /** |
| 120 | * Checks if commands should be handled differently based on the current permission mode. |
no test coverage detected