prompt_pwd: strip control characters

If a directory has a control sequence in it, then prompt_pwd (used in
the default prompt) would emit it to the console, which could cause
the terminal to interpret the escape sequence.

Strip control sequences from within prompt_pwd, in the same way as
we do in __fish_paste.fish, to sanitize it.

Closes #12629
This commit is contained in:
Peter Ammon
2026-04-12 13:15:36 -07:00
committed by Johannes Altmanninger
parent 1dac221684
commit 2bab8b5830
3 changed files with 7 additions and 1 deletions

View File

@@ -17,6 +17,7 @@ Other improvements
------------------
- History is no longer corrupted with NUL bytes when fish receives SIGTERM or SIGHUP (:issue:`10300`).
- ``fish_update_completions`` now handles groff ``\X'...'`` device control escapes, fixing completion generation for man pages produced by help2man 1.50 and later (such as coreutils 9.10).
- ``prompt_pwd`` now strips control characters.
For distributors and developers
-------------------------------

View File

@@ -26,7 +26,8 @@ function prompt_pwd --description 'short CWD for the prompt'
or set -l fish_prompt_pwd_full_dirs 1
for path in $argv
set -l tmp (__fish_unexpand_tilde $path)
# Strip control characters to avoid injecting terminal escape sequences into the prompt.
set -l tmp (__fish_unexpand_tilde $path | string replace -ra '[[:cntrl:]]' '')
if test "$fish_prompt_pwd_dir_length" -eq 0
echo $tmp

View File

@@ -14,3 +14,7 @@ prompt_pwd -D 0 /usr/share/fish/prompts
prompt_pwd -d1 -D 3 /usr/local/share/fish/prompts
# CHECK: /u/l/share/fish/prompts
# Ensure control characters in paths are stripped
prompt_pwd -d 0 /foo/(printf '\e]0;OHNO\a')bar
# CHECK: /foo/]0;OHNObar