Skip to content

fix(executor): keep empty pathname components beside globstar (Refs #2709) - #3693

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/2709-globstar-empty-components
Nov 15, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/2709-globstar-empty-components

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Problem

\*\* adjacent to empty pathname components misbehaved (issue #2709):

  • **//*.txt wrongly matched top-level files (a.txt…); GNU requires
    \*\* to consume at least one real directory level when followed by
    // (sub/c.txt, sub/deep/e.txt, x/y/z.txt only).
  • sub//**/e.txt collapsed sub// to sub/ in result names; GNU
    emits sub//deep/e.txt, sub// etc.

Root cause

  • globstar_expand ran prefix.trim_end_matches('/'), dropping every
    empty component of the literal prefix GNU hands glob_vector
    verbatim (glob.c:1293-1299 dir_name, glob.c:1058-1109
    glob_dir_to_array dir+name join).
  • expand_multi_globstar dropped all empty segments, losing both the
    literal // and the // after ** that changes its arity
    (glob.c:1188-1210 folds only **+/* sequences).
  • The multi-walk had no representation for the "" cwd placeholder
    drop (GX_ADDCURDIR + filename[0] rescue, glob.c:1348-1417) or for
    ./.. literal dir components.

Fix

src/executor/glob.rs:

  • Keep all but the one ** boundary slash in globstar_expand.
  • Keep empty segments in expand_multi_globstar; fold **+slashes+**.
  • collect_multi_globstar_paths tracks literal_run (a // is a real
    / inside the contiguous literal prefix, a boundary after glob/**)
    and self_slash (** self keeps the literal dir's separator:
    x/**→x/, x//**→x//, but x/*/**→x/y verbatim).
  • Suppress the . self match for ** followed by empty components.
  • ./.. bypass entry matching as literal dir components.

Validation

  • Pin issue2709_globstar_empty_component_regressions: 3/3 green
    (was 1/3 on master).
  • GNU probe battery (26 cells: **//x, sub//**, sub//**//e.txt,
    .//**//e.txt, x//y, x/*/**, s*//, trailing-slash forms):
    byte-identical to WSL GNU Bash 5.3.x.
  • Neighbor glob/globstar pins green; pre-existing env/live-pin reds
    identical on master (issue0015 ×2, issue1029 ×3 errexit,
    issue1321 ×4 env, issue2647, issue3205, issue332).
  • cargo test --lib red set = {issue2084} (baseline).
  • RUSTFLAGS="-D warnings" cargo check clean.

…2709)

GNU glob.c keeps dir_name strings verbatim: 'sub//' + '**' emits
'sub//...' names, a '**' followed by empty components ('**//x') must
consume at least one real level, and 'x//y' keeps both slashes. The
walk trimmed every trailing slash off the base and dropped empty
segments entirely, collapsing 'sub//' to 'sub/' and letting '**//x'
match top-level files.

- globstar_expand keeps all but the one '**' boundary slash
  (glob.c:1293-1299 dir_name, glob.c:1058-1109 dir+name join)
- expand_multi_globstar keeps empty segments; '**' separated from a
  previous '**' only by slashes still folds (glob.c:1188-1210)
- collect_multi_globstar_paths tracks literal_run: an empty component
  contributes '/' only inside the contiguous literal prefix, and a
  '**' self emission keeps the literal dir's trailing separator while
  a matched dir emits verbatim ('x/**' -> 'x/' vs 'x/*/**' -> 'x/y')
- '**' before empty components drops the cwd placeholder self match
  (glob.c GX_ADDCURDIR + the filename[0] rescue at glob.c:1348-1417)
- '.'/'..' are literal dir components, bypassing entry matching

Validated: pin issue2709_globstar_empty_component_regressions 3/3;
GNU probe battery (26 cells: **//x, sub//**, sub//**//e.txt, .//**//,
x//y, s*//, x/*/**, trailing slashes) byte-identical to WSL GNU 5.3.x.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant