pathseg

package
v0.26.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 27, 2026 License: AGPL-3.0 Imports: 3 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

func Escapes(rel string) bool

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

func HasParent(p string) bool

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

func HasParentRaw(escaped string) bool

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

func Name(s string) bool

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

func OptionalName(s string) bool

OptionalName is Name for a route parameter that may be absent: the empty string passes, anything else must be a plain segment.

func Path

func Path(p string) bool

Path reports whether p is a relative, slash-separated path of plain segments: not empty, no leading or trailing slash, no empty segment, no "." or ".." segment, no backslash or NUL.

func Segments

func Segments(parts []string) bool

Segments reports whether every element of an already split path is a plain segment. An empty list passes; callers that need a minimum depth check it.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL