mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-04-18 22:21:15 -03:00
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:
committed by
Johannes Altmanninger
parent
1dac221684
commit
2bab8b5830
@@ -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
|
||||
-------------------------------
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user