Skip to content

Support escaped spaces inside double quotes - #19010

Merged
fdncred merged 1 commit into
nushell:mainfrom
ronisbr:fix_space_escape
Sep 10, 2026
Merged

fdncred merged 1 commit into
nushell:mainfrom
ronisbr:fix_space_escape

Conversation

@ronisbr

@ronisbr ronisbr commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

Description

Terminals such as macOS Terminal.app, iTerm2 and Ghostty escape spaces with a backslash when a
file or folder is dragged into the window, for example
/Users/mac/Downloads/a\ hourly\ list\ 1.txt. Nushell could not accept that text anywhere: a bare
word splits at the space, and "a\ b" was a parse error (unrecognized escape sequence '\ ').

In this PR, I added \ (a backslash followed by a space) to the escape sequences recognized
inside double-quoted strings. It yields a literal space and joins the existing "special" escapes
(\(, \), \{, \}, \$, \#, \~, \|, ...), which already cover the other characters those
terminals escape. The workflow becomes: type ", drop the file, type ".

Why double quotes only:

  • "a\ b" was a hard error before, so no existing script changes meaning, on any platform.
  • Single quotes and backticks stay byte-literal. The NUON spec documents backticks as literal, and
    the path completer emits raw paths inside backticks without escaping backslashes, so giving \
    a meaning there would be a breaking change (and would silently rewrite C:\dir\ file on Windows).
  • Bare-word support is not possible without breaking Windows paths such as ls C:\ D:\.

Because unescape_string is shared, the escape works in "...", $"...", external command
arguments, source/use paths and from nuon. No lexer, completion or highlighting changes were
needed. The doc comment on unescape_string that was lost in the parser file split (#18388) is
restored, and the NUON spec now lists the new escape.

"/Users/mac/Downloads/a\ hourly\ list\ 1.txt"
# => /Users/mac/Downloads/a hourly list 1.txt

ls "dir\ with\ space/file\ one.txt" | get name
# => dir with space/file one.txt

'a\ b'       # => a\ b   (unchanged)
echo `a\ b`  # => a\ b   (unchanged)

User-facing changes (Release notes)

Added \ (a backslash followed by a space) as an escape for a literal space inside double-quoted
strings, so paths that terminals escape on drag-and-drop can be pasted between double quotes
unchanged: ls "/Users/me/My\ Documents/notes\ (1).txt". Previously this was a parse error.
Single quotes, backticks and bare words are unchanged.

Additional notes

🤖 The test cases and this description was generated with Claude Code

@github-actions github-actions Bot added the A:parser Issues related to parsing label Sep 10, 2026
@fdncred

fdncred commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

I'm generally ok with this other than how sloppy and verbose AI writes descriptions. What AI meant to say above is that it only works with double quotes because in nushell double quotes interpret escapes instead of taking them literally.

Looks like a pretty easy update. It still seems odd to me that people drag and drop file names from finder to terminals.

@ronisbr

ronisbr commented Sep 10, 2026

Copy link
Copy Markdown
Contributor Author

I'm generally ok with this other than how sloppy and verbose AI writes descriptions. What AI meant to say above is that it only works with double quotes because in nushell double quotes interpret escapes instead of taking them literally.

Yeah, sorry :)

It still seems odd to me that people drag and drop file names from finder to terminals.

I do it a lot to change the directory I am working in.

@fdncred fdncred added notes:ready Indicates Ready for Release notes notes:additions Noted in "Additions" section labels Sep 10, 2026
@fdncred
fdncred merged commit 1ed063b into nushell:main Sep 10, 2026
15 checks passed
@fdncred

fdncred commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

Thanks

@github-actions github-actions Bot added this to the v0.113.0 milestone Sep 10, 2026
@ronisbr
ronisbr deleted the fix_space_escape branch September 10, 2026 18:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A:parser Issues related to parsing notes:additions Noted in "Additions" section notes:ready Indicates Ready for Release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support escape space by backslash in command line

2 participants