pathutil

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package pathutil provides path validation and normalization utilities for GitHub repository paths.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidPath = errors.New("invalid path")

ErrInvalidPath is returned when a path contains invalid characters or patterns.

View Source
var ErrPathTraversal = errors.New("path traversal not allowed")

ErrPathTraversal is returned when a path contains directory traversal attempts.

Functions

func Base

func Base(p string) string

Base returns the last element of a path. Returns "" for empty paths.

func Dir

func Dir(p string) string

Dir returns the directory portion of a path. Returns "" for files in the root directory.

func Ext

func Ext(p string) string

Ext returns the file extension of a path. Returns "" if there is no extension.

func HasPrefix

func HasPrefix(p, prefix string) bool

HasPrefix reports whether the path has the given prefix. Both paths are normalized before comparison.

func Join

func Join(elem ...string) string

Join joins path elements and normalizes the result for GitHub. Empty elements are ignored.

func Normalize

func Normalize(p string) string

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

func Split(p string) (dir, file string)

Split splits a path into directory and file components. Returns ("", filename) for files in the root directory.

func Validate

func Validate(p string) error

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

func ValidateAndNormalize(p string) (string, error)

ValidateAndNormalize validates and normalizes a path in one operation. Returns the normalized path and any validation error.

Types

This section is empty.

Jump to

Keyboard shortcuts

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