Skip to content

Commit e4202a0

Browse files
committed
[Console] Fix backslash escaping in bash completion
1 parent 726d360 commit e4202a0

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/Symfony/Component/Console/Completion/Output/BashCompletionOutput.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ public function write(CompletionSuggestions $suggestions, OutputInterface $outpu
2727
}
2828
$output->write(implode(' ', $options));
2929

30-
$output->writeln(implode(' ', $suggestions->getValueSuggestions()));
30+
$values = array_map(function ($value) {
31+
return str_replace('\\', '\\\\\\\\', $value);
32+
}, $suggestions->getValueSuggestions());
33+
34+
$output->writeln(implode(' ', $values));
3135
}
3236
}

src/Symfony/Component/Console/Resources/completion.bash

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ _sf_{{ COMMAND_NAME }}() {
1616

1717
local completecmd=("$sf_cmd" "_complete" "-sbash" "-c$cword" "-S{{ VERSION }}")
1818
for w in ${words[@]}; do
19-
completecmd+=(-i "'$w'")
19+
completecmd+=($(printf -- '-i%b' "$w"))
2020
done
2121

2222
local sfcomplete
2323
if sfcomplete=$(${completecmd[@]} 2>&1); then
24-
COMPREPLY=($(compgen -W "$sfcomplete" -- "$cur"))
24+
COMPREPLY=($(compgen -W "$sfcomplete" -- $(printf -- "%q" "$cur")))
2525
__ltrim_colon_completions "$cur"
2626
else
2727
if [[ "$sfcomplete" != *"Command \"_complete\" is not defined."* ]]; then

0 commit comments

Comments
 (0)