[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Bash not escaping escape sequences in directory names

From: Chet Ramey
Subject: Re: Bash not escaping escape sequences in directory names
Date: Mon, 24 Jan 2022 10:31:53 -0500
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.4.1

On 1/23/22 6:33 PM, Josh Harcombe wrote:

"user-controlled substitutions" was the wrong phrasing I guess, what I
meant was I was wondering if this same sanitization principle should be
applied to other things that could become part of your prompt while being
controlled by someone else, (e.g. potentially the current git branch name)
but since a) `git-check-ref-format` restricts valid branch names anyway and
b) bash should probably only care about the PS1 built in substitutions then
\W and \w are probably the only ones that would need to be sanitized.

If you're running a command substitution to add characters to your prompt
(such as the current git branch name), and you're concerned about those
characters corrupting the display, add something like `| cat -v' to the

Likewise, if you're concerned that this is a problem, you can use something
like '$(echo $PWD | cat -v)' in your prompt instead of \w and solve it today. The word expansion equivalent for \W is similar.

There is a legitimate reason to filter the result of \w and \W (as well as
\s): the non-printing characters in the result can disturb readline's

However, you can't go too far with this. Following this train to its
logical end means that `pwd' and `cd' would have to sanitize their output,
since the same thing can happen.

``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    chet@case.edu    http://tiswww.cwru.edu/~chet/

reply via email to

[Prev in Thread] Current Thread [Next in Thread]