glob
ModuleShell glob matching: PHP's fnmatch().
PHP calls the C library's fnmatch(3). The runtimes this port is held
to run on Alpine Linux, so this is musl's implementation
(src/regex/fnmatch.c) in the C.UTF-8 locale PHP runs in there:
characters are UTF-8 sequences, character classes are musl's Unicode
tables (classes), an invalid sequence in the pattern matches nothing
and one in the name only matches ? or a negated bracket, as musl reads
them.
| PHP | Rust |
|---|---|
fnmatch($pattern, $filename) (no flags) | fnmatch |
Checked against the real function by bin/compat fuzz php-std
(operation glob.fnmatch).
Contents
1 submodule, and what the module defines itself.
use php_std::glob::fnmatch;pub fn fnmatch(pattern: &[u8], filename: &[u8]) -> Result<bool, EngineError>PHP fnmatch($pattern, $filename): whether filename matches the shell
glob pattern (*, ?, [...] with !/^, ranges and [:class:],
\ escapes; * crosses / and a leading . is not special).
A null byte in either argument is the ValueError PHP throws; an
argument of 4096 bytes or more does not match (PHP warns).
use php_std::glob::fnmatch;
assert_eq!(fnmatch(b"v1.*", b"v1.2.0"), Ok(true));
assert_eq!(fnmatch(b"v?.0.0", b"v10.0.0"), Ok(false));
assert_eq!(fnmatch(b"[!a]*", b"beta"), Ok(true));glob::classes
Own pageThe code points musl puts in each [:class:] of a glob in a UTF-8
locale, as (first, last) ranges.
Generated by dumping, for every code point, whether PHP's fnmatch()
on the dev image (Alpine, musl, C.UTF-8) matches it against
[[:<class>:]] (data/glob_classes.php).