Documentation
¶
Overview ¶
Package pathutil provides path expansion and validation utilities.
Package pathutil provides path manipulation and safety validation utilities.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetDirectoryOfFile ¶
GetDirectoryOfFile returns the directory containing the given file path.
func SafeJoin ¶ added in v0.5.0
SafeJoin joins path elements and validates the result stays within the base directory. This is similar to filepath.Join but with traversal protection.
func ValidateNoPathTraversal ¶ added in v0.5.0
ValidateNoPathTraversal validates that a path doesn't contain path traversal sequences. This prevents attacks like extracting files to ../../../etc/passwd.
func ValidatePathWithinBase ¶
ValidatePathWithinBase checks if targetPath is within baseDir (no path traversal escape). This is optional validation for security-sensitive operations. Pass empty baseDir to skip validation.
func ValidateRemovalPath ¶ added in v0.5.0
ValidateRemovalPath validates that a path is safe to remove. Returns an error if the path is dangerous (empty, root, system directories).
Types ¶
type PathExpander ¶
type PathExpander struct {
// contains filtered or unexported fields
}
PathExpander provides path expansion functionality.
func NewPathExpander ¶
func NewPathExpander(renderer template.Renderer) *PathExpander
NewPathExpander creates a new PathExpander with the given template renderer.
func (*PathExpander) ExpandPath ¶
func (p *PathExpander) ExpandPath(originalPath string, currentDir string, context map[string]interface{}) (string, error)
ExpandPath expands a path with template variables and special prefixes (~, ., ./).
func (*PathExpander) SafeExpandPath ¶
func (p *PathExpander) SafeExpandPath(originalPath string, currentDir string, context map[string]interface{}, baseDir string) (string, error)
SafeExpandPath is like ExpandPath but validates the result is within baseDir. Pass empty baseDir to disable validation (same as ExpandPath).