MCPcopy Create free account
hub / github.com/anus-dev/ANUS / escapePath

Function escapePath

packages/core/src/utils/paths.ts:134–156  ·  view source on GitHub ↗
(filePath: string)

Source from the content-addressed store, hash-verified

132 * asterisks, question marks, dollar signs, backticks, quotes, hash, and other shell metacharacters.
133 */
134export function escapePath(filePath: string): string {
135 let result = '';
136 for (let i = 0; i < filePath.length; i++) {
137 const char = filePath[i];
138
139 // Count consecutive backslashes before this character
140 let backslashCount = 0;
141 for (let j = i - 1; j >= 0 && filePath[j] === '\\'; j--) {
142 backslashCount++;
143 }
144
145 // Character is already escaped if there's an odd number of backslashes before it
146 const isAlreadyEscaped = backslashCount % 2 === 1;
147
148 // Only escape if not already escaped
149 if (!isAlreadyEscaped && SHELL_SPECIAL_CHARS.test(char)) {
150 result += '\\' + char;
151 } else {
152 result += char;
153 }
154 }
155 return result;
156}
157
158/**
159 * Unescapes special characters in a file path.

Callers 2

paths.test.tsFile · 0.85
searchFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected