Document escaping and expanding of quotes on Windows
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Parsers included: - go parser (well, this is easily dealt with using `` strings) - win32 (shell-api) parser - powershell parser (for powershell commands) - powershell parsing rules for calling native commands - internal parsers of select regex applications (like grep)
authored by Vlastimil Ovčáčík · committed by Junegunn Choi · parent a33c011 · Browse files · 1 file·+39 added−0 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+39 added−0 removed
- other:+39 added−0 removed
Provenance
- Commit
e0dd2be- Tree
8fdba93- Author
Vlastimil Ovčáčík <vovcacik@github.ovcacik.org>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
a33c011
1 file changed+39 added−0 removed
modified:src/terminal_test.go+39 added
342 unmodified lines343 344 tests := []testCase{345 // reference: give{template, query, items}, want{output OR match}346 347+ /*348+ You can read each line in the following table as a pipeline that349+ consist of series of parsers that act upon your input (col. 1) and350+ each cell represents the output value.351+352+ For example:353+ - exec.Command("program.exe", `\''`)354+ - goes to win32 api which will process it transparently as it contains no special characters, see [CommandLineToArgvW][].355+ - powershell command will receive it as is, that is two arguments: a literal backslash and empty string in single quotes356+ - native command run via/from powershell will receive only one argument: a literal backslash. Because extra parsing rules apply, see [NativeCallsFromPowershell][].357+ - some¹ apps have internal parser, that requires one more level of escaping (yes, this is completely application-specific, but see terminal_test.go#TestWindowsCommands)358+359+ Character⁰ CommandLineToArgvW Powershell commands Native commands from Powershell Apps requiring escapes¹ | Being tested below360+ ---------- ------------------ ------------------------------ ------------------------------- -------------------------- | ------------------361+ " empty string² missing argument error ... ... |362+ \" literal " unbalanced quote error ... ... |363+ '\"' literal '"' literal " empty string empty string (match all) | yes364+ '\\\"' literal '\"' literal \" literal " literal " |365+ ---------- ------------------ ------------------------------ ------------------------------- -------------------------- | ------------------366+ \ transparent transparent transparent regex error |367+ '\' transparent literal \ literal \ regex error | yes368+ \\ transparent transparent transparent literal \ |369+ '\\' transparent literal \\ literal \\ literal \ |370+ ---------- ------------------ ------------------------------ ------------------------------- -------------------------- | ------------------371+ ' transparent unbalanced quote error ... ... |372+ \' transparent literal \ and unb. quote error ... ... |373+ \'' transparent literal \ and empty string literal \ regex error | no, but given as example above374+ ''' transparent unbalanced quote error ... ... |375+ '''' transparent literal ' literal ' literal ' | yes376+ ---------- ------------------ ------------------------------ ------------------------------- -------------------------- | ------------------377+378+ ⁰: charatecter or characters 'x' as an argument to a program in go's call: exec.Command("program.exe", `x`)379+ ¹: native commands like grep, git grep, ripgrep380+ ²: interpreted as a grouping quote, affects argument parser and gets removed from the result381+382+ [CommandLineToArgvW]: https://docs.microsoft.com/en-gb/windows/win32/api/shellapi/nf-shellapi-commandlinetoargvw#remarks383+ [NativeCallsFromPowershell]: https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_parsing?view=powershell-7.1#passing-arguments-that-contain-quote-characters384+ */385+386 // 1) working examples387 388 {give{`Get-Content {}`, ``, newItems(`C:\test.txt`)}, want{output: `Get-Content 'C:\test.txt'`}},389 {give{`rg -- "package" {}`, ``, newItems(`.\test.go`)}, want{output: `rg -- "package" '.\test.go'`}},249 unmodified lines