MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / normalizeUserProvidedPath

Function normalizeUserProvidedPath

cli/src/utils/image-handler.ts:73–87  ·  view source on GitHub ↗

* Normalizes a user-provided file path by handling escape sequences.

(filePath: string)

Source from the content-addressed store, hash-verified

71 * Normalizes a user-provided file path by handling escape sequences.
72 */
73function normalizeUserProvidedPath(filePath: string): string {
74 let normalized = filePath
75
76 // Handle unicode escape sequences (e.g., from terminal copy/paste)
77 normalized = normalized.replace(/\\u\{([0-9a-fA-F]+)\}|\\u([0-9a-fA-F]{4})/g, (_, bracedCode, shortCode) => {
78 const code = bracedCode || shortCode
79 const value = Number.parseInt(code, 16)
80 return Number.isNaN(value) ? _ : String.fromCodePoint(value)
81 })
82
83 // Handle shell-escaped special characters (e.g., spaces in paths)
84 normalized = normalized.replace(/\\([ \t"'(){}\[\]])/g, '$1')
85
86 return normalized
87}
88
89/**
90 * Validates if a file path is a supported image

Callers 1

resolveFilePathFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected