MCPcopy Index your code
hub / github.com/anomalyco/opencode / encodeFilePath

Function encodeFilePath

packages/app/src/context/file/path.ts:83–102  ·  view source on GitHub ↗
(filepath: string)

Source from the content-addressed store, hash-verified

81}
82
83export function encodeFilePath(filepath: string): string {
84 // Normalize Windows paths: convert backslashes to forward slashes
85 let normalized = filepath.replace(/\\/g, "/")
86
87 // Handle Windows absolute paths (D:/path -> /D:/path for proper file:// URLs)
88 if (/^[A-Za-z]:/.test(normalized)) {
89 normalized = "/" + normalized
90 }
91
92 // Encode each path segment (preserving forward slashes as path separators)
93 // Keep the colon in Windows drive letters (`/C:/...`) so downstream file URL parsers
94 // can reliably detect drives.
95 return normalized
96 .split("/")
97 .map((segment, index) => {
98 if (index === 1 && /^[A-Za-z]:$/.test(segment)) return segment
99 return encodeURIComponent(segment)
100 })
101 .join("/")
102}
103
104export function createPathHelpers(scope: () => string) {
105 const normalize = (input: string) => {

Callers 4

pathToFileUrlFunction · 0.90
buildRequestPartsFunction · 0.90
path.test.tsFile · 0.90
tabFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected