Skip to main content

is_safe_package_name

Function is_safe_package_name 

Source
pub fn is_safe_package_name(name: &str) -> bool
Expand description

What: Check whether a package name matches the strict allowlist used for install commands.

Inputs:

  • name: Candidate package name to validate.

Output:

  • true when name starts with a lowercase ASCII letter or digit and every remaining byte is one of a-z, 0-9, @, ., _, +, -.

Details:

  • Defense-in-depth gate before command construction, matching Arch’s package naming rules (lowercase only).
  • The first byte may not be - or ., so a name can never be parsed as an option (--help, -S) or a hidden path, even before the -- operand terminator that all builders emit.
  • Internal @ . _ + - remain valid, preserving lib32-*, split packages, versioned names such as python3.12, and + names.
  • Ported from Pacsea’s install/utils.rs.

§Example

use arch_toolkit::install::is_safe_package_name;

assert!(is_safe_package_name("ripgrep"));
assert!(is_safe_package_name("libc++"));
assert!(is_safe_package_name("lib32-glibc"));
assert!(!is_safe_package_name("bad;rm -rf"));
assert!(!is_safe_package_name("Upper"));
assert!(!is_safe_package_name("--help"));
assert!(!is_safe_package_name(".hidden"));
assert!(!is_safe_package_name(""));