[PATCH 0/7] lib/glob: fixes, new features, and test coverage

From: Josh Law

Date: Sun Mar 15 2026 - 13:14:39 EST


This series addresses several issues found in lib/glob.c and adds new
functionality with comprehensive test coverage.

Bug fixes:
- Normalize inverted character class ranges like [z-a] so they
match the same characters as [a-z] instead of silently matching
nothing (patch 1).
- Treat a trailing backslash as a literal '\\' character instead of
consuming the NUL terminator and matching end-of-string (patch 2).

New features:
- Accept [^...] as an alias for [!...] in character class negation,
matching the behavior of git, rsync, and bash (patch 3).
- Add glob_match_nocase() for case-insensitive pattern matching,
useful for device model strings and filter expressions where case
should not matter (patch 4).
- Add glob_validate() to check pattern syntax upfront, detecting
unclosed character classes and trailing backslashes so callers
that accept user input can reject malformed patterns with a clear
error (patch 5).

Test coverage:
- Add 47 test cases covering backslash escapes, inverted ranges,
caret negation, wildcards with empty strings, unclosed brackets,
consecutive wildcards, and special characters (patch 6).
- Add parameterized tests for glob_match_nocase() and
glob_validate() (patch 7).

Build-tested with both lib/glob.o and lib/tests/glob_kunit.o.

Josh Law (7):
lib/glob: normalize inverted character class ranges
lib/glob: treat trailing backslash as literal character
lib/glob: accept [^...] as character class negation syntax
lib/glob: add case-insensitive glob_match_nocase()
lib/glob: add glob_validate() for pattern syntax checking
lib/tests: add glob test cases for escapes, edge cases, and new
features
lib/tests: add kunit tests for glob_match_nocase() and glob_validate()

include/linux/glob.h | 2 +
lib/glob.c | 122 +++++++++++++++++++++++++++++++++++++---
lib/tests/glob_kunit.c | 124 +++++++++++++++++++++++++++++++++++++++++
3 files changed, 239 insertions(+), 9 deletions(-)

--
2.34.1