Skip to content

fix(shell): 🐛 fix unexpected double quote in Zsh#541

Open
brendanmaguire wants to merge 2 commits intodvorka:dev-3.2.0from
brendanmaguire:448/fix-unexpected-double-quotes-zsh
Open

fix(shell): 🐛 fix unexpected double quote in Zsh#541
brendanmaguire wants to merge 2 commits intodvorka:dev-3.2.0from
brendanmaguire:448/fix-unexpected-double-quotes-zsh

Conversation

@brendanmaguire
Copy link
Copy Markdown

  • 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 #488

* 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
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/hstr.c

"\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;"
Copy link

Copilot AI Jan 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The unquoted variable expansion echo ${BUFFER} is unsafe and can lead to data corruption. When BUFFER is unquoted:

  1. Word splitting will occur on whitespace, so a command like "git commit -m 'my message'" would be incorrectly split
  2. Pathname expansion (globbing) will occur, so wildcards like * or ? will be expanded
  3. 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.

Suggested change
"\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;"

Copilot uses AI. Check for mistakes.
Comment thread man/hstr.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;
Copy link

Copilot AI Jan 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The unquoted variable expansion echo ${BUFFER} is unsafe and can lead to data corruption. When BUFFER is unquoted:

  1. Word splitting will occur on whitespace, so a command like "git commit -m 'my message'" would be incorrectly split
  2. Pathname expansion (globbing) will occur, so wildcards like * or ? will be expanded
  3. 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.

Copilot uses AI. Check for mistakes.
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;
Copy link

Copilot AI Jan 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The unquoted variable expansion echo ${BUFFER} is unsafe and can lead to data corruption. When BUFFER is unquoted:

  1. Word splitting will occur on whitespace, so a command like "git commit -m 'my message'" would be incorrectly split
  2. Pathname expansion (globbing) will occur, so wildcards like * or ? will be expanded
  3. 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.

Suggested change
{ 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;

Copilot uses AI. Check for mistakes.
@dvorka dvorka changed the base branch from master to dev-3.2.0 January 24, 2026 08:18
@dvorka dvorka changed the title Fix unexpected double quote in zsh feat(tiocsti): ✨ fix unexpected double quote in Zsh Jan 24, 2026
@dvorka dvorka changed the title feat(tiocsti): ✨ fix unexpected double quote in Zsh fix(shell): 🐛 fix unexpected double quote in Zsh Jan 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unexpected double quote

3 participants