You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
-i matches multi-character sequences via Unicode case folding where GNU matches one #32
Under -i, uu_grep lets a single-character pattern match a multi-character sequence when that sequence is a Unicode case-folding of one character — e.g. st (folds from the ligatures ſt/st), ss (from ß), or ff/fi/ffi (from ff/fi/ffi). GNU under LC_ALL=C folds case 1:1 and matches a single character. The input here is plain ASCII, so this is not the locale/encoding limitation — the extra matching comes from the case folder, not from byte-vs-codepoint handling.
Found by the differential fuzzer (fuzz_grep).
Rust (incorrect)
$ printf'st\n'| ./target/release/grep -o -i '[[:alpha:]]'
st
# one match spanning two characters
GNU (correct)
$ printf'st\n'| LC_ALL=C /usr/bin/grep -o -i '[[:alpha:]]'
s
t
# two separate single-character matches
More cases (Rust → GNU): ss → ss vs s/s; ff → ff vs f/f; ffi → ffi vs f/f/i. It is order-sensitive (st merges but ts does not) and changes match counts, not just -o output.
This is a shortcoming of us not handling LC_* at all just yet. It always operates as if it was en_US.UTF-8 and I believe in that case grep folds it as per Unicode, right?
Good point that LC_* is the larger missing seam, but I do not think GNU grep's UTF-8 behavior is full Unicode case folding in the sense Oniguruma is applying here.
That makes the issue a little different from just “we behave as en_US.UTF-8 until locale support exists.” The current behavior lets one regex atom match a multi-character input sequence ([[:alpha:]] matching st, ss, ffi, etc.), which changes -o output and counts. GNU appears to avoid those multi-character fold expansions even outside the C-locale discussion.
So I think the eventual fix should probably be: keep broader LC_* support as the long-term locale seam, but make the current ignore-case matcher avoid multi-codepoint/full-fold expansions for GNU compatibility. I have not opened a PR yet because I want to check whether Oniguruma exposes a clean option/syntax flag for “simple folds only”; if it does not, a hand-rolled workaround around character classes and -o boundaries could get brittle quickly.
Activity
lhecker commentedon Jun 4, 2026
This is a shortcoming of us not handling
LC_*at all just yet. It always operates as if it wasen_US.UTF-8and I believe in that case grep folds it as per Unicode, right?wondr-wclabs commentedon Jun 5, 2026
Good point that
LC_*is the larger missing seam, but I do not think GNU grep's UTF-8 behavior is full Unicode case folding in the sense Oniguruma is applying here.GNU's own manual calls out this exact class of case:
ßnormally capitalizes to the two-character stringSS, but undergrep -iit does not matchSS(and even matching capitalẞis documented as locale/implementation-sensitive): https://www.gnu.org/software/grep/manual/html_node/Matching-Control.htmlThat makes the issue a little different from just “we behave as en_US.UTF-8 until locale support exists.” The current behavior lets one regex atom match a multi-character input sequence (
[[:alpha:]]matchingst,ss,ffi, etc.), which changes-ooutput and counts. GNU appears to avoid those multi-character fold expansions even outside the C-locale discussion.So I think the eventual fix should probably be: keep broader
LC_*support as the long-term locale seam, but make the current ignore-case matcher avoid multi-codepoint/full-fold expansions for GNU compatibility. I have not opened a PR yet because I want to check whether Oniguruma exposes a clean option/syntax flag for “simple folds only”; if it does not, a hand-rolled workaround around character classes and-oboundaries could get brittle quickly.