Help us shape the future of Go! Take the 2026 Go Developer Survey

path

package
v1.109.0 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExpandEnvRefs added in v1.97.0

func ExpandEnvRefs(s string) string

ExpandEnvRefs resolves only the plain `${env.VAR}` form (see jsEnvRef) against the OS environment, leaving every other `$`-shaped substring (including `$VAR` and `${VAR}`) untouched. Use it for fields whose values may legitimately contain literal `$` (e.g. env values forwarded to subprocesses), where a full os.Expand pass would mangle them (issue #2615). Unset variables expand to the empty string, matching the JS-template semantics; a debug log makes that observable since the resulting value is otherwise indistinguishable from a legitimate "".

func ExpandHomeDir added in v1.58.0

func ExpandHomeDir(path string) (string, error)

ExpandHomeDir expands a leading home-directory reference in a path. It expands "~", "~/...", and "~\\..." on Windows. Other tilde forms, such as "~user/...", are returned unchanged.

func ExpandPath added in v1.44.0

func ExpandPath(p string) string

ExpandPath expands shell-like patterns in a file path:

  • ~ or ~/ at the start is replaced with the user's home directory
  • Environment variables like ${HOME} or $HOME are expanded
  • The JS-template form ${env.HOME} is accepted as an alias for ${HOME}

func ExpandWorkingDir added in v1.97.0

func ExpandWorkingDir(field, p string) string

ExpandWorkingDir expands a working-directory field like ExpandPath, and warns when a non-empty value expands to empty (typically an unset variable, e.g. `working_dir: ${env.UNSET}`). Callers fall back to a default directory in that case, which would otherwise be a silent surprise for commands that mutate files (#2615).

func IsWithin added in v1.66.0

func IsWithin(p, dir string) bool

IsWithin reports whether p is equal to dir or contained by dir.

func NormalizeEnvRefs added in v1.89.0

func NormalizeEnvRefs(s string) string

NormalizeEnvRefs rewrites the JS-template form `${env.VAR}` to the shell form `${VAR}`, so os.Expand-based callers also accept the JS-style syntax used elsewhere in the config (issue #2615). Richer JS expressions are left untouched; see jsEnvRef.

func RelativeTo added in v1.66.0

func RelativeTo(p, baseDir string) string

RelativeTo returns p relative to baseDir when both paths are absolute and filepath.Rel can compute a relative path. Otherwise it returns p cleaned.

func ShortenHome added in v1.66.0

func ShortenHome(p string) string

ShortenHome replaces the current user's home directory prefix with "~".

func ShortenHomeDir added in v1.66.0

func ShortenHomeDir(p, homeDir string) string

ShortenHomeDir replaces a leading homeDir prefix with "~".

func ValidatePathInDirectory

func ValidatePathInDirectory(path, allowedDir string) (string, error)

Types

This section is empty.

Jump to

Keyboard shortcuts

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