safepath

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2026 License: GPL-3.0 Imports: 3 Imported by: 0

Documentation

Overview

Package safepath provides root-anchored path joins that reject traversal. All operations are pure functions with no I/O side effects.

Index

Constants

This section is empty.

Variables

View Source
var ErrAbsolute = errors.New("safepath: name must not be absolute")

ErrAbsolute is returned when the name is an absolute path.

View Source
var ErrEmpty = errors.New("safepath: name must not be empty")

ErrEmpty is returned when the name is empty.

View Source
var ErrEscapesRoot = errors.New("safepath: path escapes root")

ErrEscapesRoot is returned when a name resolves to a path outside the root.

View Source
var ErrNUL = errors.New("safepath: name must not contain NUL")

ErrNUL is returned when the name contains a NUL byte.

Functions

func Anchor

func Anchor(root, name string) (string, error)

Anchor returns filepath.Join(root, name) after verifying the cleaned result remains within root. It rejects names that are:

  • empty
  • absolute paths
  • contain NUL bytes
  • resolve to a path outside root after cleaning (e.g. via ".." segments)

Types

This section is empty.

Jump to

Keyboard shortcuts

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