mirror of
https://github.com/neovim/neovim.git
synced 2025-10-04 17:06:30 +00:00
fix: make_filter_cmd for :! powershell
Problem:
`Start-Process` requires the command to be split into the shell
command and its arguments. Previously it was done by parsing, which
didn't handle cases such as
- commands with escaped space in their filepath
- quoted commands with space in their filepath
Solution:
Use
- `pwsh -Command` instead of `Start-Process`
- `Get-Content` instead of `-RedirectStandardInput`
- `Out-File` instead of `-RedirectStandardOutput`
(cherry picked from commit b4d42bb905
)
This commit is contained in:

committed by
github-actions[bot]
![github-actions[bot]](/assets/img/avatar_default.png)
parent
9e784a53b4
commit
bb9c5c3f60
@@ -562,16 +562,16 @@ function module.set_shell_powershell(fake)
|
||||
assert(found)
|
||||
end
|
||||
local shell = found and (iswin() and 'powershell' or 'pwsh') or module.testprg('pwsh-test')
|
||||
local set_encoding = '[Console]::InputEncoding=[Console]::OutputEncoding=[System.Text.Encoding]::UTF8;'
|
||||
local set_encoding = '[Console]::InputEncoding=[Console]::OutputEncoding=[System.Text.UTF8Encoding]::new();'
|
||||
local cmd = set_encoding..'Remove-Item -Force '..table.concat(iswin()
|
||||
and {'alias:cat', 'alias:echo', 'alias:sleep'}
|
||||
and {'alias:cat', 'alias:echo', 'alias:sleep', 'alias:sort'}
|
||||
or {'alias:echo'}, ',')..';'
|
||||
module.exec([[
|
||||
let &shell = ']]..shell..[['
|
||||
set shellquote= shellxquote=
|
||||
let &shellcmdflag = '-NoLogo -NoProfile -ExecutionPolicy RemoteSigned -Command ]]..cmd..[['
|
||||
let &shellpipe = '2>&1 | Out-File -Encoding UTF8 %s; exit $LastExitCode'
|
||||
let &shellredir = '-RedirectStandardOutput %s -NoNewWindow -Wait'
|
||||
let &shellredir = '2>&1 | Out-File -Encoding UTF8 %s; exit $LastExitCode'
|
||||
]])
|
||||
return found
|
||||
end
|
||||
|
@@ -642,12 +642,12 @@ describe('shell :!', function()
|
||||
if iswin() then
|
||||
feed(':4verbose %!sort /R<cr>')
|
||||
screen:expect{
|
||||
any=[[Executing command: .?Start%-Process sort %-ArgumentList "/R" %-RedirectStandardInput .* %-RedirectStandardOutput .* %-NoNewWindow %-Wait]]
|
||||
any=[[Executing command: .?Get%-Content .* | & sort /R 2>&1 | Out%-File %-Encoding UTF8 .*; exit $LastExitCode]]
|
||||
}
|
||||
else
|
||||
feed(':4verbose %!sort -r<cr>')
|
||||
screen:expect{
|
||||
any=[[Executing command: .?Start%-Process sort %-ArgumentList "%-r" %-RedirectStandardInput .* %-RedirectStandardOutput .* %-NoNewWindow %-Wait]]
|
||||
any=[[Executing command: .?Get%-Content .* | & sort %-r 2>&1 | Out%-File %-Encoding UTF8 .*; exit $LastExitCode]]
|
||||
}
|
||||
end
|
||||
feed('<CR>')
|
||||
|
Reference in New Issue
Block a user