mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
fix(powershell): wrong length allocation for ":%w !" #20530
Problem:
The calculation of `len` in `make_filter_cmd` for powershell falls short
by one character for the following ex command:
:%w !sort
This command satisfies these conditions:
- `itmp` is not null
- `otmp` is null
__NOTE__ that other shells circumvent this bug only because of `len`
allocation for six extra characters: a pair of curly braces and four
spaces:
cfdb4cbada/src/nvim/ex_cmds.c (L1551-L1554)
If allocation for these six characters are removed, then bash also faces
the same bug.
Solution:
Add allocation for 6 extra bytes. 1 would do, but let's keep powershell
in sync with other shells as much as possible.
This commit is contained in:
parent
572cd8031d
commit
2f1fd15554
@ -1382,7 +1382,7 @@ char *make_filter_cmd(char *cmd, char *itmp, char *otmp)
|
||||
: 0;
|
||||
|
||||
if (itmp != NULL) {
|
||||
len += is_pwsh ? strlen(itmp) + sizeof("& { Get-Content " " | & " " }") - 1
|
||||
len += is_pwsh ? strlen(itmp) + sizeof("& { Get-Content " " | & " " }") - 1 + 6 // +6: #20530
|
||||
: strlen(itmp) + sizeof(" { " " < " " } ") - 1;
|
||||
}
|
||||
if (otmp != NULL) {
|
||||
|
@ -662,4 +662,33 @@ describe('shell :!', function()
|
||||
1]])
|
||||
end
|
||||
end)
|
||||
|
||||
it(':{range}! without redirecting to buffer', function()
|
||||
local screen = Screen.new(500, 10)
|
||||
screen:attach()
|
||||
insert([[
|
||||
3
|
||||
1
|
||||
4
|
||||
2]])
|
||||
feed(':4verbose %w !sort<cr>')
|
||||
if is_os('win') then
|
||||
screen:expect{
|
||||
any=[[Executing command: .?sort %< .*]]
|
||||
}
|
||||
else
|
||||
screen:expect{
|
||||
any=[[Executing command: .?%(sort%) %< .*]]
|
||||
|
||||
}
|
||||
end
|
||||
feed('<CR>')
|
||||
helpers.set_shell_powershell(true)
|
||||
feed(':4verbose %w !sort<cr>')
|
||||
screen:expect{
|
||||
any=[[Executing command: .?& { Get%-Content .* | & sort }]]
|
||||
}
|
||||
feed('<CR>')
|
||||
helpers.expect_exit(command, 'qall!')
|
||||
end)
|
||||
end)
|
||||
|
Loading…
Reference in New Issue
Block a user