mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-04 08:24:40 +01:00
fix: escape curly braces for the prompt cwd (#4511)
If a directory was named for example '{RED}', that would get interpreted as a color string and the prompt would not show the direcotry name and would color it instead. Using dir names like '{{foo}}' or simply '{' would break the prompt outright. There was not much documentation on the prompt formating, but it seems that escaping a curly by doubling it makes the prompt display all curlies correctly. fixes #4381
This commit is contained in:
parent
7331d8aee5
commit
8da06b4446
3 changed files with 41 additions and 1 deletions
23
news/pwd-curly-escape.rst
Normal file
23
news/pwd-curly-escape.rst
Normal file
|
@ -0,0 +1,23 @@
|
|||
**Added:**
|
||||
|
||||
* <news item>
|
||||
|
||||
**Changed:**
|
||||
|
||||
* Curly braces { } in directory names are now escaped in the prompt
|
||||
|
||||
**Deprecated:**
|
||||
|
||||
* <news item>
|
||||
|
||||
**Removed:**
|
||||
|
||||
* <news item>
|
||||
|
||||
**Fixed:**
|
||||
|
||||
* <news item>
|
||||
|
||||
**Security:**
|
||||
|
||||
* <news item>
|
16
tests/prompt/test_cwd.py
Normal file
16
tests/prompt/test_cwd.py
Normal file
|
@ -0,0 +1,16 @@
|
|||
from xonsh.prompt.cwd import _replace_home_cwd
|
||||
from xonsh.built_ins import XSH
|
||||
|
||||
|
||||
def test_cwd_escapes_curly_brackets_with_more_curly_brackets():
|
||||
XSH.env["PWD"] = "{foo}"
|
||||
assert _replace_home_cwd() == "{{foo}}"
|
||||
|
||||
XSH.env["PWD"] = "{{foo}}"
|
||||
assert _replace_home_cwd() == "{{{{foo}}}}"
|
||||
|
||||
XSH.env["PWD"] = "{"
|
||||
assert _replace_home_cwd() == "{{"
|
||||
|
||||
XSH.env["PWD"] = "}}"
|
||||
assert _replace_home_cwd() == "}}}}"
|
|
@ -27,7 +27,8 @@ def _replace_home(x):
|
|||
|
||||
|
||||
def _replace_home_cwd():
|
||||
return _replace_home(XSH.env["PWD"])
|
||||
pwd = XSH.env["PWD"].replace("{", "{{").replace("}", "}}")
|
||||
return _replace_home(pwd)
|
||||
|
||||
|
||||
def _collapsed_pwd():
|
||||
|
|
Loading…
Add table
Reference in a new issue