MCPcopy Index your code
hub / github.com/jetify-com/devbox / splitPathOrOpaque

Function splitPathOrOpaque

nix/flake/flakeref.go:515–540  ·  view source on GitHub ↗

splitPathOrOpaque splits a URL path by '/'. If the path is empty, it splits the opaque instead. Splitting happens before unescaping the path or opaque, ensuring that path elements with an encoded '/' (%2F) are not split. For example, "/dir/file%2Fname" becomes the elements "dir" and "file/name". The

(u *url.URL, n int)

Source from the content-addressed store, hash-verified

513// For example, "/dir/file%2Fname" becomes the elements "dir" and "file/name".
514// The count limits the number of substrings per [strings.SplitN]
515func splitPathOrOpaque(u *url.URL, n int) ([]string, error) {
516 upath := u.EscapedPath()
517 if upath == "" {
518 upath = u.Opaque
519 }
520 upath = strings.TrimSpace(upath)
521 if upath == "" {
522 return nil, nil
523 }
524
525 // We don't want an empty element if the path is rooted.
526 if upath[0] == '/' {
527 upath = upath[1:]
528 }
529 upath = path.Clean(upath)
530
531 var err error
532 split := strings.SplitN(upath, "/", n)
533 for i := range split {
534 split[i], err = url.PathUnescape(split[i])
535 if err != nil {
536 return nil, err
537 }
538 }
539 return split, nil
540}
541
542// buildEscapedPath escapes and joins path elements for a URL flake ref. The
543// resulting path is cleaned according to url.JoinPath.

Callers 2

parseURLRefFunction · 0.85
parseGitHubRefFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected