Skip to content

fix(prompt): strip \[ \] ignore-markers on every PS1 render path - #480

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/ps1-marker-render
Oct 10, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/ps1-marker-render

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

closes #431

Problem

PS1 \[/\] ignore-markers rendered as literal text (or leaked as raw \x01/\x02 bytes) in some render paths: the oh-my-bash inretio theme shape, and bash-it themes leaking up to 4 marker fragments. wt70's fix stripped the markers only at the piped -i driver's terminal write; the remaining consumers still emitted them unstripped.

Root cause

Three consumers turn a PS1 into renderable text; only one stripped the RL_PROMPT_START/END_IGNORE equivalents:

  • piped -i driver terminal write (script_driver.rs) — already covered by wt70
  • Shell::expand_prompt_string / expand_prompt_string_mut — the host line-editor channel niubash's BashPrompt renders through — unstripped
  • ${var@P} prompt transform (GNU subst.c string_transform P) — leaked the raw \x01/\x02 bytes to stdout — unstripped

Fix

  • New shared boundary prompt_expansion::strip_prompt_ignore_markers (readline display.c expand_prompt: the markers are width-accounting delimiters, never display payload).
  • expand_prompt_string, expand_prompt_string_mut and the @P transform all strip; the driver-side filter is folded into that boundary.
  • Real control bytes (ESC color sequences) are untouched, so color and cursor-positioning geometry survive.

Tests

New tests/issue431_prompt_marker_render_regressions.rs:

  • inretio theme shape: no marker bytes, no literal \[/\], ESC[01;32m preserved
  • bash-it PROMPT_COMMAND + command-substitution shape: 0 fragments across the stream
  • host channel (expand_prompt_string_mut) marker-free
  • ${PS1@P}: markers stripped, ESC payload and prompt text intact

Existing suites green (prompt family: issue393/421/433, pb10k marker test, 630 lib tests + full integration sweep identical to the master baseline; the handful of pre-existing failures are environment path-mapping issues reproduced on clean master).

#431)

wt70 stripped the prompt-ignore markers only at the piped -i driver's
terminal write. The remaining render consumers still emitted the markers
unstripped:

- Shell::expand_prompt_string / expand_prompt_string_mut (the host
  line-editor channel niubash's BashPrompt renders through)
- the ${var@P} prompt transform (parameter_transforms), which leaked
  the raw \x01/\x02 bytes to stdout

Both now funnel through prompt_expansion::strip_prompt_ignore_markers
(readline display.c expand_prompt assembles the display without the
width-accounting delimiters), and the driver-side filter is folded into
that shared boundary. ESC and other real control bytes are untouched, so
color and cursor-positioning geometry survive.

Regressions pin the inretio theme shape (marker bytes and literal
\\[ \\] absent, ESC[01;32m present), a bash-it PROMPT_COMMAND +
command-substitution shape (0 fragments across the stream), the host
channel, and ${PS1@P}.

closes #431
@caomengxuan666
caomengxuan666 merged commit 10ff8a3 into master Oct 10, 2026
7 of 8 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/ps1-marker-render branch October 10, 2026 02:58
caomengxuan666 added a commit that referenced this pull request Oct 10, 2026
…els strip the ignore markers (rubash#431 scope fix)

#480 funneled the ${var@P} prompt transform through
strip_prompt_ignore_markers alongside the render channels. For a PS1 the
strip is display semantics (readline display.c expand_prompt assembles
the prompt without the width-accounting bytes), but a script-visible
transform result must keep bytes that were IN the value: upstream
bash-tests exp8.sub:26 runs `recho ${var@P}` against
var=$'x\001y\177z' and GNU 5.3.0 records `argv[1] = <x^Ay^?z>` in
exp.right:253 — the literal \x01 survives. %q probes on WSL GNU 5.3.0
and Git 5.2.37 agree ($'x\001y\177z').

The strip ate the literal byte (`xy^?z`), a GNU-parity regression that
the exp suite-slice snapshot pinned as a CI failure — the red
'GNU regression goldens and canaries' job every PR inherited since
#480 was exactly this one byte.

${var@P} is decode_prompt_string and nothing else again:
- the \`\\[\\]\` markers are already handled per GNU parse.y:6609-6622
  inside decode_prompt_string (dropped when no line editor is active,
  marker bytes when emacs/vi is on) — the prompt_transform_strips_
  ignore_markers regression stays green on that branch, not on a strip;
- the render channels (expand_prompt_string{,_mut}, the piped -i
  driver) keep their strip: a terminal-bound prompt must not carry the
  width-accounting bytes. niubash's BashPrompt bridge is unaffected.

Gate: issue431 regressions 4/4, parameter-transform tests green, full
regression suite 26/27 locally (the snapshot leg is the OS-dependent
comsub slice this machine cannot reproduce; the CI artifact from the
previous commit proves the runner records the committed bytes for all
13 slices once this revert lands).
caomengxuan666 added a commit that referenced this pull request Oct 10, 2026
…ot env + CI golden-refresh artifact (#496)

* tests/regression: airtight env for suite snapshots + CI golden-refresh artifact (drift protocol)

The 'GNU regression goldens and canaries' job has been red on every PR
since 10ff8a3 (#480): the ${var@P} marker-strip fix (#431) legitimately
changed the exp slice's stdout, and tests/regression/snapshots/exp.snap
was never re-recorded — every later PR inherited that red (26 passed /
1 failed, upstream_suite_slice_snapshots).

Two structural fixes so a stale baseline cannot snowball again:

1. run_suite_snapshot now runs the suites in the same airtight
   environment as the goldens (env_clear + machine-infrastructure
   whitelist + PATH/HOME), instead of only removing OLDPWD/BASH_ENV/
   WINUXSH_ROOT. The old ambient-env pass-through made snapshot bytes
   machine-dependent: exp.tests:416 executes `${THIS_SH} -c ...`, so any
   shell that exports THIS_SH records argv lines a clean runner never
   emits, and shell-option variables (BASHOPTS/SHELLOPTS/POSIXLY_CORRECT
   classes) are exactly what the alias-expansion machinery keys on.
   A snapshot byte that depends on ambient env cannot be a baseline.

2. The regression job records the snapshots on the runner and uploads
   them as the regression-snapshots artifact (always()). When the
   comparison fails because committed .snap files are stale, that
   artifact is the runner-true replacement content — no more
   hand-transcribing the truncated 40-line panic window.

Module header documents the re-record protocol: a snapshot diff IS a
semantic change; a recording commit must cite the behavior-fix issue/PR
per slice, or the red baseline ships itself forward.

Gate: cargo fmt clean; snapshot suites byte-identical on the recording
path; full regression suite green modulo the stale exp.snap this PR
re-records next.

* fix(prompt): ${var@P} keeps literal control bytes — only render channels strip the ignore markers (rubash#431 scope fix)

#480 funneled the ${var@P} prompt transform through
strip_prompt_ignore_markers alongside the render channels. For a PS1 the
strip is display semantics (readline display.c expand_prompt assembles
the prompt without the width-accounting bytes), but a script-visible
transform result must keep bytes that were IN the value: upstream
bash-tests exp8.sub:26 runs `recho ${var@P}` against
var=$'x\001y\177z' and GNU 5.3.0 records `argv[1] = <x^Ay^?z>` in
exp.right:253 — the literal \x01 survives. %q probes on WSL GNU 5.3.0
and Git 5.2.37 agree ($'x\001y\177z').

The strip ate the literal byte (`xy^?z`), a GNU-parity regression that
the exp suite-slice snapshot pinned as a CI failure — the red
'GNU regression goldens and canaries' job every PR inherited since
#480 was exactly this one byte.

${var@P} is decode_prompt_string and nothing else again:
- the \`\\[\\]\` markers are already handled per GNU parse.y:6609-6622
  inside decode_prompt_string (dropped when no line editor is active,
  marker bytes when emacs/vi is on) — the prompt_transform_strips_
  ignore_markers regression stays green on that branch, not on a strip;
- the render channels (expand_prompt_string{,_mut}, the piped -i
  driver) keep their strip: a terminal-bound prompt must not carry the
  width-accounting bytes. niubash's BashPrompt bridge is unaffected.

Gate: issue431 regressions 4/4, parameter-transform tests green, full
regression suite 26/27 locally (the snapshot leg is the OS-dependent
comsub slice this machine cannot reproduce; the CI artifact from the
previous commit proves the runner records the committed bytes for all
13 slices once this revert lands).
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.

[P2] PS1 \[ \] markers render literally in some paths (inretio theme; bash-it themes leak <=4 fragments)

1 participant