git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] git-prompt.sh: don't assume the shell expands the value of PS1

From
Junio C Hamano <gitster@pobox.com>
Date
May 20, 2014, 18:38 UTC
Message-ID
<xmqqbnusz46e.fsf@gitster.dls.corp.google.com>
In-Reply-To
<1400540137-29994-1-git-send-email-rhansen@bbn.com>
Richard Hansen <rhansen@bbn.com> writes:
Show 13 quoted lines
> Not all shells subject the prompt string to parameter expansion.  Test
> whether the shell will expand the value of PS1, and use the result to
> control whether raw ref names are included directly in PS1.
>
> This fixes a regression introduced in commit 8976500 ("git-prompt.sh:
> don't put unsanitized branch names in $PS1"):  zsh does not expand PS1
> by default, but that commit assumed it did.  The bug resulted in
> prompts containing the literal string '${__git_ps1_branch_name}'
> instead of the actual branch name.
>
> Reported-by: Caleb Thompson <caleb@calebthompson.io>
> Signed-off-by: Richard Hansen <rhansen@bbn.com>
> ---
Thanks, applied.
Show 21 quoted lines
> To prevent a regression like this from happening again, I plan on
> adding new zsh test cases and expanding the bash test cases (to test
> the behavior with 'shopt -u promptvars').  I'd like the zsh tests to
> cover the same stuff as the bash tests.  These are the steps I am
> considering:
>
>   1. delete the last test case in t9903 ("prompt - zsh color pc mode")
>   2. add two new functions to t/lib-bash.sh:
>          ps1_expansion_enable () { shopt -s promptvars; }
>          ps1_expansion_disable () { shopt -u promptvars; }
>   3. loop over the relevant test cases twice:  once after calling
>      ps1_expansion_enable and once after calling ps1_expansion_disable
>      (with appropriate adjustments to the expected output)
>   4. move the test cases in t9903 to a separate library file and
>      source it from t9903-bash-prompt.sh
>   5. create two new files:
>        * t/lib-zsh.sh (same as t/lib-bash.sh but tweaked for zsh)
>        * t/t9904-zsh-prompt.sh (same as t/t9903-bash-prompt.sh but
>          tweaked for zsh)
>
> Does this approach sound reasonable?

Sounds like a plan, especially if step 4 does a reasonable job of factoring out as much common stuff as possible.

Previous: Richard HansenNext: Richard Hansen
Message 2 of 35 in “git-prompt.sh: don't assume the shell expands the value of PS1”
  1. git-prompt.sh: don't assume the shell expands the value of PS1Richard Hansen, May 19, 2014
  2. Junio C HamanoMay 20, 2014
  3. 00/10 Zsh prompt testsRichard Hansen, May 27, 2014
  4. 01/10 t9903: remove Zsh test from the suite of Bash prompt testsRichard Hansen, May 27, 2014
  5. 02/10 t9903: put the Bash pc mode prompt test cases in a functionRichard Hansen, May 27, 2014
  6. 03/10 t9903: move test name prefix to a separate variableRichard Hansen, May 27, 2014
  7. 04/10 t9903: run pc mode tests again with PS1 expansion disabledRichard Hansen, May 27, 2014
  8. 05/10 t9903: include "Bash" in test names via new $shellname varRichard Hansen, May 27, 2014
  9. 06/10 t9903: move PS1 color code variable definitions to lib-bash.shRichard Hansen, May 27, 2014
  10. 07/10 t9903: move prompt tests to a new lib-prompt-tests.sh fileRichard Hansen, May 27, 2014
  11. 08/10 lib-prompt-tests.sh: put all tests inside a functionRichard Hansen, May 27, 2014
  12. 09/10 lib-prompt-tests.sh: add variable for string that encodes percent in PS1Richard Hansen, May 27, 2014
  13. 10/10 t9904: new __git_ps1 tests for ZshRichard Hansen, May 27, 2014
  14. Thomas RastMay 29, 2014
  15. 11/10 fixup! t9904: new __git_ps1 tests for ZshRichard Hansen, May 29, 2014
  16. 00/11 Zsh prompt testsRichard Hansen, Jun 4, 2014
  17. 01/11 t9903: remove Zsh test from the suite of Bash prompt testsRichard Hansen, Jun 4, 2014
  18. 02/11 t9903: put the Bash pc mode prompt test cases in a functionRichard Hansen, Jun 4, 2014
  19. 03/11 t9903: move test name prefix to a separate variableRichard Hansen, Jun 4, 2014
  20. 04/11 t9903: run pc mode tests again with PS1 expansion disabledRichard Hansen, Jun 4, 2014
  21. 05/11 t9903: include "Bash" in test names via new $shellname varRichard Hansen, Jun 4, 2014
  22. 06/11 t9903: move PS1 color code variable definitions to lib-bash.shRichard Hansen, Jun 4, 2014
  23. 07/11 t9903: move prompt tests to a new lib-prompt-tests.sh fileRichard Hansen, Jun 4, 2014
  24. 08/11 lib-prompt-tests.sh: put all tests inside a functionRichard Hansen, Jun 4, 2014
  25. 09/11 lib-prompt-tests.sh: add variable for string that encodes percent in PS1Richard Hansen, Jun 4, 2014
  26. 10/11 test-lib: make it possible to override how test code is eval'dRichard Hansen, Jun 4, 2014
  27. Junio C HamanoJun 5, 2014
  28. Richard HansenJun 6, 2014
  29. Junio C HamanoJun 6, 2014
  30. 11/11 t9904: new __git_ps1 tests for ZshRichard Hansen, Jun 4, 2014
  31. Torsten BögershausenJun 10, 2014
  32. Richard HansenJun 10, 2014
  33. brian m. carlsonJun 11, 2014
  34. Richard HansenJun 11, 2014
  35. brian m. carlsonJun 11, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.