Skip to content

Strip the blank guard from in-process pipeline stage operands - #4171

Merged
caomengxuan666 merged 1 commit into
unixwin:masterfrom
jhermelink:fix/pipeline-stage-escaped-blank-guard
Nov 24, 2026
Merged

caomengxuan666 merged 1 commit into
unixwin:masterfrom
jhermelink:fix/pipeline-stage-escaped-blank-guard

Conversation

@jhermelink

Copy link
Copy Markdown
Contributor

Problem

Reported via niubash 1.5.1:

$ echo xxx > a\ b
$ cat a\ b | wc -l      # cat: a b: No such file or directory

The failing operand is a<U+E401> b: the ANSI_C_IFS_GUARD carrier that an escaped blank lexes to leaks into the file name.

Cause

cat as a pipeline stage runs in-process (PipelineSlot::Cat) and expands its operands itself. Together with expand_pipeline_stage_arg_words (used by the echo/printf/tput arms) it only dropped CTLESC and never stripped the guard, unlike command_prepare::materialize_expanded_command_word for simple commands.

It only shows up with a DEBUG trap armed (oh-my-niu installs one for its preexec hook); without a trap the pipeline takes a path that strips the guard.

Fix

One helper, unguard_pipeline_operand, drops CTLESC pairs and the guard; both sites use it.

Tests

New tests/pipeline_escaped_blank_operand_regressions.rs (pipe-driven -i). The DEBUG-trap test fails without the fix and passes with it; the other two are regression guards. cli_tests has the same 16 failures with and without this change.

An escaped blank (a\ b) lexes to ANSI_C_IFS_GUARD + blank. The cat
pipeline arm and expand_pipeline_stage_arg_words expand their operands
themselves and never stripped the guard, so with a DEBUG trap armed
(oh-my-niu's preexec hook) `cat a\ b | wc -l` opened "a<U+E401> b" and
failed with No such file or directory. Route the operands through one
helper that drops CTLESC pairs and the guard, like command_prepare does
for simple commands.
@caomengxuan666
caomengxuan666 merged commit ce1eb28 into unixwin:master Nov 24, 2026
10 of 12 checks passed
@caomengxuan666

Copy link
Copy Markdown
Member

CAPTAIN-VERIFY — merged (head 8689c1da). Thank you for the precise field report and the fix.

Mechanism, as verified. Two operand-materialization contracts disagreed: the simple-command path (materialize_expanded_command_word, command_prepare.rs) strips the U+E401 ANSI_C_IFS_GUARD carrier from expanded words, while the in-process pipeline stage arm (expand_pipeline_stage_arg_words) stripped only CTLESC — so an escaped-space filename reached cat still carrying the guard byte, but only when the pipeline actually took the in-process arm, which is why the DEBUG trap (oh-my-niu's preexec hook) had to be armed to reproduce it.

Fix shape. One helper, unguard_pipeline_operand, at all 7 call sites, delegating to the existing E400-aware strip_ansi_c_ifs_guard in markers.rs — no new marker protocol, and a user-typed literal U+E401 stays preserved. Noted for the record: the PR body has no explicit deletion section, but the diff is exactly seven verbatim inline strips folded into the one helper (pipeline_exec.rs +20/−7), so the accounting is clean.

Evidence. CI: all functional legs pass; census unique names are only the three documented rotators (issue3949 amp-coproc, issue2771, issue2340 wait pair) — 0 unique true reds; goldens red is exactly the two pre-existing #4038 faces. Fail-first was re-run independently by the captain's lane on the pushed head: all 3 new pins green on the fixed tree; with only the src fix reverted (base pipeline_exec.rs restored, tests kept), the DEBUG-trap pin goes red with the exact field signature — rubash: cat: a\u{e401} b: No such file or directory — in both the | wc -l and | cat shapes. The main pin stays green without the fix, correctly: unarmed, the pipeline never takes the in-process arm, so that pin is a regression guard and the DEBUG-trap pin is the discriminating one. The tree was restored byte-identical to the pushed head after the check.

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.

2 participants