Repository navigation
fix(complete): compgen -G returns literal-path matches and globs under set -f (Refs #4272) - #4278
Merged
Merged
Conversation
…r set -f (Refs #4272) Refs #4272 (not Fixes). gen_globpat_matches (pcomplete.c) hands the -G pattern straight to glob_filename; the subst.c word-expansion admission gates never apply. rubash routed compgen through pathname_expand_word, whose gates dropped two faces: a pattern without unquoted metacharacters never produced a result (glob_vector's stat fast path returns the dequoted literal when the file exists), and under `set -f` every -G pattern returned nothing (noglob is a glob_expand_word_list check, not a glob.c one). Add compgen_globpat_expand_word in glob.rs: the same machinery as pathname_expand_word with the word-expansion gates (empty word, byte whitelist, noglob, whole-word unquoted_glob_pattern_p) skipped; glob.c's per-component glob_pattern_p admission decides instead. Both compgen call sites in complete.rs (the builtin and the compspec completion attempt) use it. Ordinary expansion is untouched: `set -f` still suppresses echo fi*, nullglob/failglob keep their word-list behavior, and neither leaks into compgen. Pins: tests/issues_4200_4299/issue4272_compgen_globpat_literal_ and_noglob.rs (5 tests: literal face incl. escapes/trailing slash/absolute/nonexistent, noglob face + expansion guard, empty pattern, invalid bracket + prefix filter, nullglob/failglob neutrality). Oracle-verified against bash 5.3.20 on every case.
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.
UNVERIFIED-BY-CAPTAIN
Refs #4272 (not Fixes — captain closes after verification).
What
compgen -Gdiverged from GNU on two faces (ShiomiHC's report, captain-confirmed against the bash 5.3.20 oracle, triage comment on #4272):set -f,compgen -Greturned nothing at all, even for real patterns. GNU still matches.Root cause
pcomplete.c
gen_globpat_matcheshands the pattern straight toglob_filename; the subst.c word-expansion admission gates never apply. rubash routed compgen throughpathname_expand_word, whose gates are exactly those word-expansion checks: the byte whitelist +unquoted_glob_pattern_p(a pattern-free word is provably not a pattern for expansion) and thenoglobearly return (aglob_expand_word_listcheck, not a glob.c one).Fix
New
compgen_globpat_expand_wordinsrc/executor/glob.rs: the same machinery aspathname_expand_word(sharedpathname_expand_word_gatedbody) with the word-expansion gates skipped — glob.c's own per-componentglob_pattern_padmission (stat fast path inglob_vector, only_filename branch inglob_filename) decides instead. Both compgen call sites insrc/builtins/complete.rs(the builtin and the compspec completion attempt, which sharegen_globpat_matchesin GNU) use it.Ordinary expansion is untouched, and the pins guard the separation:
set -fstill suppressesecho fi*; nullglob/failglob keep their word-list behavior and neither leaks into compgen (a-Gno-match stays a quiet rc 1 under both).Consequences that fall out of the machinery, all oracle-verified byte-for-byte against bash 5.3.20: literal file/dir returned dequoted (
fix,fix/a.dat,fix/a\.dat→fix/a.dat), trailing-slash words returned verbatim with no existence check (fix/,nope/,fix/a.dat/),./fix,fix/.,fix//a.datpreserved, nonexistent literal paths and paths under nonexistent directories return nothing (rc 1), empty pattern yields one empty match (rc 0), invalid bracket text is literal (returned only when the file exists).Verification (lane, devin-mac)
75a7947breproduced both faces (every literal case rc 1, everyset -fcase rc 1); after the fix the full 21-case table matches the oracle verbatim, includingabs ok.tests/issues_4200_4299/issue4272_compgen_globpat_literal_and_noglob.rs, 5 tests — bucket runs 38/38.#[cfg(windows)]and cannot run on the mac lane.Net production lines: src +48/−9 (glob.rs +46/−7 incl. doc comments, complete.rs +2/−2 for the two call sites); tests +182.