Documentation
¶
Overview ¶
Package pathseg is the one definition of a plain path segment, shared by every place that turns client-supplied names into repository paths, coordinates, file names or upstream URLs.
A plain segment is not empty, not "." or "..", and holds no "/", backslash or NUL. A name that passes can neither climb out of the directory it is joined to nor alias a sibling ("a//b" against "a/b"), whichever separator a client, file system or archive tool reads into it.
The functions work on decoded text. A caller that holds a still percent-encoded path (a URL's EscapedPath) uses HasParentRaw, which decodes each segment before looking at it; decoding a value that is already final would turn a literal "%" into an escape of its own.
Callers add their own character-set and length rules on top; this package only answers the traversal question.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Escapes ¶
Escapes reports whether rel, a path made relative to a base by filepath.Rel or path.Clean, leads out of that base: it is ".." or starts with "../" (or the OS separator form).
func HasParent ¶
HasParent reports whether p, an operator-supplied or archive-supplied path of any shape (absolute, with empty segments, with either separator), has a ".." segment. It is the check for paths that are legitimately not plain, such as an absolute storage directory, where Path would refuse the leading slash.
func HasParentRaw ¶
HasParentRaw is HasParent for a still percent-encoded path, as url.URL.EscapedPath returns it: every segment is decoded first, so "%2e%2e" and "..%2f" count, and an escape that does not decode counts as a hit.
func Name ¶
Name reports whether s is one plain segment: a file or directory name that is not empty, not "." or "..", and has no "/", backslash or NUL.
func OptionalName ¶
OptionalName is Name for a route parameter that may be absent: the empty string passes, anything else must be a plain segment.
Types ¶
This section is empty.