MCPcopy Create free account
hub / github.com/microsoft/typescript-go / simpleNormalizePath

Function simpleNormalizePath

internal/tspath/path.go:514–528  ·  view source on GitHub ↗
(path string)

Source from the content-addressed store, hash-verified

512}
513
514func simpleNormalizePath(path string) (string, bool) {
515 // Most paths don't require normalization
516 if !hasRelativePathSegment(path) {
517 return path, true
518 }
519 // Some paths only require cleanup of `/./` or leading `./`
520 simplified := strings.ReplaceAll(path, "/./", "/")
521 trimmed := strings.TrimPrefix(simplified, "./")
522 if trimmed != path && !hasRelativePathSegment(trimmed) && !(trimmed != simplified && strings.HasPrefix(trimmed, "/")) {
523 // If we trimmed a leading "./" and the path now starts with "/", we changed the meaning
524 path = trimmed
525 return path, true
526 }
527 return "", false
528}
529
530// hasRelativePathSegment reports whether p contains ".", "..", "./", "../", "/.", "/..", "//", "/./", or "/../".
531func hasRelativePathSegment(p string) bool {

Callers 2

NormalizePathFunction · 0.70

Calls 1

hasRelativePathSegmentFunction · 0.85

Tested by

no test coverage detected