Documentation
¶
Overview ¶
Package pathutil provides path validation and normalization utilities for GitHub repository paths.
Index ¶
- Variables
- func Base(p string) string
- func Dir(p string) string
- func Ext(p string) string
- func HasPrefix(p, prefix string) bool
- func Join(elem ...string) string
- func Normalize(p string) string
- func Split(p string) (dir, file string)
- func Validate(p string) error
- func ValidateAndNormalize(p string) (string, error)
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidPath = errors.New("invalid path")
ErrInvalidPath is returned when a path contains invalid characters or patterns.
var ErrPathTraversal = errors.New("path traversal not allowed")
ErrPathTraversal is returned when a path contains directory traversal attempts.
Functions ¶
func HasPrefix ¶
HasPrefix reports whether the path has the given prefix. Both paths are normalized before comparison.
func Join ¶
Join joins path elements and normalizes the result for GitHub. Empty elements are ignored.
func Normalize ¶
Normalize normalizes a path for GitHub API operations. It performs the following transformations:
- Cleans the path (removes redundant separators, etc.)
- Removes leading slashes
- Converts backslashes to forward slashes
- Returns empty string for root paths (".", "/", "")
func Split ¶
Split splits a path into directory and file components. Returns ("", filename) for files in the root directory.
func Validate ¶
Validate checks if a path is valid for GitHub repository operations. It returns an error if the path contains:
- Directory traversal sequences (..)
- Null bytes or other control characters
- Invalid characters for GitHub paths
An empty path is considered valid (represents root).
func ValidateAndNormalize ¶
ValidateAndNormalize validates and normalizes a path in one operation. Returns the normalized path and any validation error.
Types ¶
This section is empty.