You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Support escaped spaces inside double quotes - #19010
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.txtls"dir\ with\ space/file\ one.txt"|getname# => 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.
Tests added in tests/parsing/escaping.rs: the reporter's exact path, interpolation, the \\ ordering, proof that single quotes and backticks stay literal, an end-to-end ls/cd on a
directory with a space, and an external command receiving a single argument.
The book's list of double-quote escapes (nushell.github.io, "Working with strings") needs the
new entry after merge.
🤖 The test cases and this description was generated with Claude Code
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.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 bareword 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 recognizedinside double-quoted strings. It yields a literal space and joins the existing "special" escapes
(
\(,\),\{,\},\$,\#,\~,\|, ...), which already cover the other characters thoseterminals 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.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\ fileon Windows).ls C:\ D:\.Because
unescape_stringis shared, the escape works in"...",$"...", external commandarguments,
source/usepaths andfrom nuon. No lexer, completion or highlighting changes wereneeded. The doc comment on
unescape_stringthat was lost in the parser file split (#18388) isrestored, and the NUON spec now lists the new escape.
User-facing changes (Release notes)
Added
\(a backslash followed by a space) as an escape for a literal space inside double-quotedstrings, 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
\remains out of scope because of Windowspaths, as discussed in the issue).
tests/parsing/escaping.rs: the reporter's exact path, interpolation, the\\ordering, proof that single quotes and backticks stay literal, an end-to-endls/cdon adirectory with a space, and an external command receiving a single argument.
new entry after merge.
🤖 The test cases and this description was generated with Claude Code