Repository navigation
fix(#695): force byte-wise bracket ranges everywhere, and pin it with a scanner - #699
Merged
Merged
Conversation
…lation Red on purpose. The fix is not in this commit. Two halves. The scanner (tests/test_locale_ranges_695.py) reads source on every platform and reports every ASCII letter range in a shipped shell script that is not matched under LC_ALL=C. It is red on 14 sites today. Three places in this tree already carried the fix before #695 -- config(), _remember_cfg_flatten_cache_valid_value, lib-slug.sh's LC_ALL=C sed -- each found separately, one bug report at a time; this is the general form, so the next one is a finding at authoring time instead. The behavioural half (tests/test_id_guards_locale_695.py) covers the two sites #698's measured matrix showed actually break, both reached through `[[ =~ ]]`: _remember_cfg_flatten_cache_valid_line -- a config key carrying an `I` makes its cache line read as malformed, so the config-data cache is refused and every hook re-reads and re-flattens the config, forever, silently. A performance floor nothing reports. _remember_normalize_win_path -- drive `I:` stops being recognised, and its `tr '[:lower:]' '[:upper:]'` maps a lower-case `i:` drive to a dotted `İ` under Turkish rules: two bytes where one ASCII letter has to go. What #698 measured, on ubuntu-latest / bash 5.2 / localedef-built tr_TR.UTF-8, and why the scope is what it is: [[ =~ ]] over [A-Z], [a-z], [a-zA-Z], [A-Za-z0-9_] loses I and i [[ =~ ]] over [A-Za-z] GAINS é case patterns, and ${v//[!...]/} do not move Both failure directions are real, and only the regex path collates; bash's own glob matcher compares bytes. The `case` guards are therefore listed in the scanner's allowlist with that measurement as their stated reason rather than excluded from the scan -- one libc and one bash is not a licence to stop looking, and POSIX does permit a case range to collate. The locale probe both modules share accepts a locale only after watching this machine's bash fail under it, and builds one with localedef when the runner ships none. Part of #695 Co-Authored-By: Max <noreply>
…at hold them Green half of the previous commit's red. Thirteen `local LC_ALL=C` insertions, each scoped to one function and restoring the caller's locale on return. Two of them are live bugs that #698's measured matrix identified, both reached through `[[ =~ ]]`: _remember_cfg_flatten_cache_valid_line (scripts/log.sh) validated each config-data cache line against ^_RCFG_[A-Za-z0-9_]+=. A config key carrying an I made the line read as malformed under Turkish collation, so the cache was refused and every hook fell back to re-reading and re-flattening the config on every invocation, permanently, with nothing said. Confirmed red on the ubuntu legs of the previous commit: VALID became REJECTED. _remember_normalize_win_path (scripts/resolve-paths.sh, mirrored in scripts/lib-env-cache.sh) stopped recognising the drive I:, and its `tr '[:lower:]' '[:upper:]'` mapped a lower-case i: drive to a dotted İ under Turkish case rules -- two bytes where one ASCII letter has to go. Forcing C fixes the range and the case mapping together. The other eleven are `case` and substitution sites, which the matrix cleared: only the regex path collates. One line makes them immune anyway and leaves the scanner no exception to carry. Also here, because the previous commit's CI said so rather than because I reasoned it: The drive-letter legs failed with exit 127, not with a wrong answer -- `_remember_normalize_win_path` is `unset -f`'d at resolve-paths.sh:340 once resolution is done, so sourcing the script does not leave it callable. Extracted by regex instead, the same route tests/test_save_session_marker_unreadable_625.py already takes for ts_marker_read and for the same recorded reason. Paired with two new C-locale legs that run on every platform, so a harness that stops working fails loudly everywhere instead of skipping in silence -- which is exactly how it hid the first time. scripts/lib-memory-dir.sh is byte-pinned against origin/main (tests/test_case_divergence_298.py), so both insertions into it are declared in _SANCTIONED_DIVERGENCE with their reason, the way #429 and #662 already are. Part of #695 Co-Authored-By: Max <noreply>
fdaviddpt
force-pushed
the
fix/695-locale-ranges
branch
from
September 15, 2026 13:48
fe27560 to
2652353
Compare
This was referenced Sep 15, 2026
fdaviddpt
added a commit
that referenced
this pull request
Sep 15, 2026
…e the tag (#701) The v0.33.0 release audit (round 1, token rel-0330-429b3dd1) returned six findings, none in a blocking row. Five are fixed here; the sixth is filed as #700. **The scanner credited a nested function's declaration to its parent.** _function_spans closed a function at the first `}` at column 0, on the stated assumption that no function is defined inside another. #696 broke that assumption: capture_was_seen() is defined at column 0 inside _remember_deferred_phase(), so the outer span was computed as ending at the inner function's brace and the inner's `local LC_ALL=C` was credited to 148 outer lines that have none. Neither PR contains this -- #696 has no scanner, #699 has no nesting -- it existed only once both had landed, which is the kind of thing only a whole-delta audit sees. Nothing falls through it today (a direct sweep of those lines finds no ranges), but the scanner is the entire standing defence for a class that already shipped a total-failure bug. Now a stack, with a nested fixture pinning both halves. **`local LC_ALL=C` never reached the `tr` child.** `local` on a name the environment never exported leaves it unexported, so on a host whose language comes from LANG alone -- what setting a system language actually produces -- the drive-letter uppercase still ran under Turkish rules and mapped `i` to the dotted `İ`. My own test in #699 passed because its harness exports LC_ALL, so `local` shadowed an already-exported name: it passed for a reason that does not hold on a real host. The new control puts a recording `tr` on PATH and asserts what locale it was actually called under, which runs on every platform and does not need a glibc runner to fail. The changelog fragment that claimed this was fixed is corrected in the same commit. **An unmeasured file size laundered into 0**, in two places, which made _remember_emit_file's own "no usable size" arm unreachable from its only caller: `0` is a digit string and `0 -gt 16384` is false, so a file of any size took the read path that #660's own threshold exists to keep it off -- 4MB measured at 24.1s on windows-latest, on the session-start foreground path. The batched `wc -c` can fail wholesale, leaving every file in that state at once. Unknown is now kept distinct from zero end to end, and the compact-mode notice says `size unknown` rather than printing `0 bytes` for a file nobody measured. **The deferred default-path control asserted one of the three records its own docstring named.** It now polls both that this fixture's storage mode can produce, and says why the third needs external storage and where it is covered instead. Local suite: 2483 passed, 58 skipped. The one failure on the way was this repo's own blanket-win32-skip guard catching a triage row I had not written yet -- added. Part of #695
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #697 (base is its branch, so the diff here is only this work;
GitHub retargets to
mainwhen #697 merges).What #698 measured
#695 fixed one site. The obvious next question was how many others there are,
and the answer needed a glibc runner -- macOS's libc does not collate bracket
ranges at all, so nothing can be observed locally. #698 is the throwaway
diagnostic that got the matrix, on
ubuntu-latest/ bash 5.2 / alocaledef-builttr_TR.UTF-8:[[ =~ ]][A-Z]vsI[[ =~ ]][a-z]vsi[[ =~ ]][a-zA-Z]vsIandi[[ =~ ]][A-Za-z0-9_]vsID[[ =~ ]][A-Za-z]vsécase[A-Za-z]:/*vsI:/xcase*[!A-Za-z0-9._-]*vsSESS-Iandé${v//[!a-zA-Z0-9]/-}Both failure directions are real -- a range that loses
I, and the same rangegaining
é-- but only through[[ =~ ]], which glibc'sregcompmatchesby collation. bash's own glob matcher, behind
caseand${v//[!...]/},compares bytes and did not move.
That is narrower than I assumed before measuring, and it cut the change down:
an earlier draft of this branch restructured all eight of the hooks'
entry guards behind a new sourced library, which the matrix says fixes nothing.
Reverted.
What this changes
Thirteen one-line
local LC_ALL=Cinsertions, each scoped to one function,plus the scanner and the behavioural tests. Two of the thirteen are live bugs:
_remember_cfg_flatten_cache_valid_line(scripts/log.sh) -- a config keycarrying an
Imakes its cache line read as malformed, so the config-datacache is refused and every hook re-reads and re-flattens the config, forever,
with nothing said. A permanent performance floor that no log line mentions.
_remember_normalize_win_path(scripts/resolve-paths.sh, mirrored inscripts/lib-env-cache.sh) -- driveI:stops being recognised. Itstr '[:lower:]' '[:upper:]'is the second half: under Turkish rules alower-case
i:drive upper-cases to a dottedİ, two bytes in a slot thatmust hold one ASCII letter.
The other eleven are
caseor substitution sites inside functions, where themeasurement says nothing is broken today and one line makes them immune anyway.
The eight that were left alone
The hooks' top-level entry guards (
agy-stop-hook.sh,post-tool-hook.sh,session-end-hook.sh,session-start-hook.sh) stay exactly as they are. Theyare
casepatterns, which the matrix cleared, and reaching a shared helperwould mean moving the guard later in the file -- the guard's position at the
point of entry is the guarantee. They sit in the scanner's ALLOWLIST with that
measurement written out as the reason, rather than being excluded from the
scan: one libc and one bash is not a licence to stop looking, and POSIX does
permit a
caserange to collate.Test-first
The first commit is tests only and is red: the scanner on 14 sites, plus the
two behavioural modules on the Linux legs. The fix follows.
Part of #695
[AI-generated]