Skip to content

fix(prompt): \D{} unknown strftime specs keep the %; unclosed brace formats - #1189

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/1099-prompt-strftime-unknown-spec
Oct 23, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/1099-prompt-strftime-unknown-spec

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Fixes #1099

Status on master

PR #1111 already fixed two of the three reported escapes (\l now yields the ttyname(0) basename else tty; \D{} now defaults to %X). One reported case still diverged, plus one adjacent \D edge found while verifying against parse.y:

PS1='\D{%N}'; echo "${PS1@P}"     # GNU 5.3.20 (WSL): %N    rubash master: N
PS1='\D{abc';  echo "${PS1@P}"     # GNU: abc               rubash master: \D{abc

Root cause & fix

  1. Unknown conversion lost its %. strftime_subset's fallback arm emitted only the specifier char, based on a claim that glibc drops % for unknown conversions. A direct glibc probe shows the opposite — glibc emits unknown conversions verbatim, percent kept:

    strftime(b,64,"%N",tm) -> "%N";  strftime(b,64,"%Q",tm) -> "%Q";  strftime(b,64,"%E",tm) -> "%E"

    GNU delegates \D{fmt} (parse.y:6390-6425) and %(fmt)T (printf.def:584-636) to the system strftime, so WSL GNU bash 5.3.20 prints %N for both repros. Note on the issue's expected output: the reporter's oracle was Android, whose bionic strftime emits N; the repo's canonical oracle is WSL GNU 5.3.x on glibc, which emits %N — this PR matches glibc. Fix: the fallback arm now pushes % plus the specifier char. The same strftime_subset serves \D, %(fmt)T, and HISTTIMEFORMAT rendering, so all three align.

  2. Unclosed \D{fmt still formats under GNU. parse.y:6398-6400 stops the format run at } or NUL alike; c stays 0 so add_string does not re-emit the \D prefix — \D{abc formats abc. rubash echoed the literal. decode_prompt_date_escape now formats on either terminator.

Before / after

case GNU 5.3.20 (WSL) master this PR
PS1='\l' ${PS1@P} tty tty tty
PS1='\D{%N}' %N N %N
PS1='\D{}' 11:12:45 11:12:40 11:12:40
PS1='x\D' x\D x\D x\D
PS1='\D{abc' abc \D{abc abc
printf '%(%N)T\n' -1 %N N %N

Tests

tests/issue1099_prompt_escape_edges.rs: 6 cases covering all the above. cargo test --release --test issue1099_prompt_escape_edges: 6/6 green; cargo test --release --test regression: 78/78 green.

Generated with Devin

…ormats (rubash#1099)

Two remaining \D{fmt} divergences vs GNU after the \l/\D{} repairs:

- strftime_subset's fallback arm dropped the % from an unknown
  conversion, emitting `x` for `%x`. GNU delegates the format to the
  system strftime (parse.y:6390-6425 for \D; printf.def:584-636 for
  %()T), and glibc strftime emits an unknown conversion VERBATIM —
  percent included. Probe-verified on WSL GNU bash 5.3.20 + glibc:
  \D{%N} -> %N, %(%N)T -> %N, strftime("%Q"/"%E") -> %Q/%E.
  (The issue's Android-bionic oracle emits `N`; the repo oracle is
  WSL glibc, which keeps `%N`.)
- An unclosed \D{fmt run still formats under GNU: the scan at
  parse.y:6398-6400 stops at `}` or NUL alike, `c` stays 0 so
  add_string does not re-emit `\D`. rubash echoed the literal
  `\D{fmt` text instead.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@caomengxuan666
caomengxuan666 merged commit 6027d7a into master Oct 23, 2026
8 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/1099-prompt-strftime-unknown-spec branch October 23, 2026 08:54
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.

[bug] Prompt escapes: \l empty, \D{%N} keeps %, \D{} empty

1 participant