(input: string)
| 17 | } |
| 18 | |
| 19 | export function unquoteGitPath(input: string) { |
| 20 | if (!input.startsWith('"')) return input |
| 21 | if (!input.endsWith('"')) return input |
| 22 | const body = input.slice(1, -1) |
| 23 | const bytes: number[] = [] |
| 24 | |
| 25 | for (let i = 0; i < body.length; i++) { |
| 26 | const char = body[i]! |
| 27 | if (char !== "\\") { |
| 28 | bytes.push(char.charCodeAt(0)) |
| 29 | continue |
| 30 | } |
| 31 | |
| 32 | const next = body[i + 1] |
| 33 | if (!next) { |
| 34 | bytes.push("\\".charCodeAt(0)) |
| 35 | continue |
| 36 | } |
| 37 | |
| 38 | if (next >= "0" && next <= "7") { |
| 39 | const chunk = body.slice(i + 1, i + 4) |
| 40 | const match = chunk.match(/^[0-7]{1,3}/) |
| 41 | if (!match) { |
| 42 | bytes.push(next.charCodeAt(0)) |
| 43 | i++ |
| 44 | continue |
| 45 | } |
| 46 | bytes.push(parseInt(match[0], 8)) |
| 47 | i += match[0].length |
| 48 | continue |
| 49 | } |
| 50 | |
| 51 | const escaped = |
| 52 | next === "n" |
| 53 | ? "\n" |
| 54 | : next === "r" |
| 55 | ? "\r" |
| 56 | : next === "t" |
| 57 | ? "\t" |
| 58 | : next === "b" |
| 59 | ? "\b" |
| 60 | : next === "f" |
| 61 | ? "\f" |
| 62 | : next === "v" |
| 63 | ? "\v" |
| 64 | : next === "\\" || next === '"' |
| 65 | ? next |
| 66 | : undefined |
| 67 | |
| 68 | bytes.push((escaped ?? next).charCodeAt(0)) |
| 69 | i++ |
| 70 | } |
| 71 | |
| 72 | return new TextDecoder().decode(new Uint8Array(bytes)) |
| 73 | } |
| 74 | |
| 75 | export function decodeFilePath(input: string) { |
| 76 | try { |
no test coverage detected