module

Hwaro::Utils::PathUtils

Instance methods

glob_match?(pattern : String, path : String) : Bool

File.match? that treats a malformed glob as non-matching instead of raising File::BadPatternError, so a single config typo can't crash a build or deploy.

Source
resolves_within?(path : String, root : String) : Bool

True when path, with all symbolic links resolved, lies inside root (also fully resolved). Used to stop symlinked source files from publishing content that lives outside the project — e.g. a static/leak -> ~/.ssh/id_rsa symlink would otherwise be copied into the public output. In-repo symlinks resolve back within the root and are kept. Returns false on a dangling/unreadable path rather than raising.

Source
sanitize_path(path : String) : String

Sanitize path to prevent directory traversal and normalize separators

This method performs the following operations:

  1. URL-decodes the path (repeated until stable to catch double-encoding)
  2. Removes null bytes
  3. Splits into segments and rejects ".." components
  4. Rejoins with "/" separator

Example: sanitize_path("/foo/../bar//baz/") # => "foo/bar/baz" sanitize_path("%2Ffoo%2Fbar") # => "foo/bar" sanitize_path("....//etc/passwd") # => "etc/passwd"

Source