fix(shell): 🐛 fix unexpected double quote in Zsh#541
fix(shell): 🐛 fix unexpected double quote in Zsh#541brendanmaguire wants to merge 2 commits intodvorka:dev-3.2.0from
Conversation
* Previously double quotes would be added when invoking hstr using `Ctrl+R` due to the BUFFER been passed as an argument to hstr * Changed how hstr is invoked to pipe the BUFFER in and then continue reading from /dev/tty Fixes dvorka#488
There was a problem hiding this comment.
Pull request overview
This PR fixes an issue where double quotes would unexpectedly appear in the hstr interface when invoking it with Ctrl+R in zsh if the current buffer contained spaces. The fix changes how the BUFFER variable is passed to hstr, switching from passing it as a command-line argument to piping it via stdin.
Changes:
- Modified the zsh integration function to pipe BUFFER content to hstr instead of passing it as an argument
- Updated all three locations where this function is defined: test file, source code, and man page
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| test/sh/tiotcsi-function-zsh.sh | Updated test script to use echo ${BUFFER} | hstr instead of hstr ${BUFFER} |
| src/hstr.c | Updated C code that generates zsh configuration to use the new piping approach |
| man/hstr.1 | Updated manual page documentation with the new zsh configuration syntax |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| "\n zle -I" | ||
| "\n { HSTR_OUT=\"$( { </dev/tty hstr ${BUFFER}; } 2>&1 1>&3 3>&- )\"; } 3>&1;" | ||
| "\n { HSTR_OUT=\"$( { echo ${BUFFER} | hstr </dev/tty; } 2>&1 1>&3 3>&- )\"; } 3>&1;" |
There was a problem hiding this comment.
The unquoted variable expansion echo ${BUFFER} is unsafe and can lead to data corruption. When BUFFER is unquoted:
- Word splitting will occur on whitespace, so a command like "git commit -m 'my message'" would be incorrectly split
- Pathname expansion (globbing) will occur, so wildcards like * or ? will be expanded
- Special characters like newlines, tabs, and backslashes may not be preserved correctly
The safe approach would be to quote the variable: echo "${BUFFER}" or use printf '%s\n' "${BUFFER}" to avoid echo's interpretation of backslash sequences.
| "\n { HSTR_OUT=\"$( { echo ${BUFFER} | hstr </dev/tty; } 2>&1 1>&3 3>&- )\"; } 3>&1;" | |
| "\n { HSTR_OUT=\"$( { printf '%s\n' \"${BUFFER}\" | hstr </dev/tty; } 2>&1 1>&3 3>&- )\"; } 3>&1;" |
| hstr_no_tiocsti() { | ||
| zle -I | ||
| { HSTR_OUT="$( { </dev/tty hstr ${BUFFER}; } 2>&1 1>&3 3>&- )"; } 3>&1; | ||
| { HSTR_OUT="$( { echo ${BUFFER} | hstr </dev/tty; } 2>&1 1>&3 3>&- )"; } 3>&1; |
There was a problem hiding this comment.
The unquoted variable expansion echo ${BUFFER} is unsafe and can lead to data corruption. When BUFFER is unquoted:
- Word splitting will occur on whitespace, so a command like "git commit -m 'my message'" would be incorrectly split
- Pathname expansion (globbing) will occur, so wildcards like * or ? will be expanded
- Special characters like newlines, tabs, and backslashes may not be preserved correctly
The safe approach would be to quote the variable: echo "${BUFFER}" or use printf '%s\n' "${BUFFER}" to avoid echo's interpretation of backslash sequences.
| hstr_no_tiocsti() { | ||
| zle -I | ||
| { HSTR_OUT="$( { </dev/tty hstr ${BUFFER}; } 2>&1 1>&3 3>&- )"; } 3>&1; | ||
| { HSTR_OUT="$( { echo ${BUFFER} | hstr </dev/tty; } 2>&1 1>&3 3>&- )"; } 3>&1; |
There was a problem hiding this comment.
The unquoted variable expansion echo ${BUFFER} is unsafe and can lead to data corruption. When BUFFER is unquoted:
- Word splitting will occur on whitespace, so a command like "git commit -m 'my message'" would be incorrectly split
- Pathname expansion (globbing) will occur, so wildcards like * or ? will be expanded
- Special characters like newlines, tabs, and backslashes may not be preserved correctly
The safe approach would be to quote the variable: echo "${BUFFER}" or use printf '%s\n' "${BUFFER}" to avoid echo's interpretation of backslash sequences.
| { HSTR_OUT="$( { echo ${BUFFER} | hstr </dev/tty; } 2>&1 1>&3 3>&- )"; } 3>&1; | |
| { HSTR_OUT="$( { printf '%s\n' "${BUFFER}" | hstr </dev/tty; } 2>&1 1>&3 3>&- )"; } 3>&1; |
Ctrl+Rdue to the BUFFER been passed as an argument to hstrFixes #488