MCPcopy Create free account
hub / github.com/OpenAtomFoundation/SmartIDE / stripPathShortcuts

Function stripPathShortcuts

cli/pkg/k8s/filespec.go:142–161  ·  view source on GitHub ↗

stripPathShortcuts removes any leading or trailing "../" from a given path

(p string)

Source from the content-addressed store, hash-verified

140
141// stripPathShortcuts removes any leading or trailing "../" from a given path
142func stripPathShortcuts(p string) string {
143 newPath := p
144 trimmed := strings.TrimPrefix(newPath, "../")
145
146 for trimmed != newPath {
147 newPath = trimmed
148 trimmed = strings.TrimPrefix(newPath, "../")
149 }
150
151 // trim leftover {".", ".."}
152 if newPath == "." || newPath == ".." {
153 newPath = ""
154 }
155
156 if len(newPath) > 0 && string(newPath[0]) == "/" {
157 return newPath[1:]
158 }
159
160 return newPath
161}

Callers 2

isRelativeFunction · 0.85
StripShortcutsMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected