Skip to content

Commit d53b830

Browse files
committed
fix(rsync,scp): remove file-type marks from "ls -F" properly
The type-classifier characters for named pipes (|) and sockets (=) were not properly removed. These are escaped by a backslash before removing, so the backslashes are left. In this patch, we remove the type-classifier characters before performing the backslash escaping.
1 parent 837a009 commit d53b830

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

completions/ssh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,8 @@ _comp_xfunc_scp_compgen_remote_files()
519519
# shellcheck disable=SC2090
520520
_files=$(ssh -o 'Batchmode yes' "$_userhost" \
521521
command ls -aF1dL "$_path*" 2>/dev/null |
522-
command sed -e 's/'"$_comp_cmd_scp__path_esc"'/'"$_escape_replacement"'/g' -e 's/[*@|=]$//g' \
522+
command sed -e 's/[*@|=]$//g' \
523+
-e 's/'"$_comp_cmd_scp__path_esc"'/'"$_escape_replacement"'/g' \
523524
-e 's/[^/]$/& /g')
524525
fi
525526
_comp_compgen -R split -l -- "$_files"
@@ -555,8 +556,9 @@ _comp_xfunc_scp_compgen_local_files()
555556
else
556557
_comp_compgen -RU files split -l -- "$(
557558
command ls -aF1dL "${files[@]}" 2>/dev/null |
558-
command sed -e "s/$_comp_cmd_scp__path_esc/\\\\&/g" \
559-
-e 's/[*@|=]$//g' -e 's/[^/]$/& /g' -e "s/^/${1-}/"
559+
command sed -e 's/[*@|=]$//g' \
560+
-e "s/$_comp_cmd_scp__path_esc/\\\\&/g" \
561+
-e 's/[^/]$/& /g' -e "s/^/${1-}/"
560562
)"
561563
fi
562564
}

test/t/test_scp.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22

33
import pytest
44

5-
from conftest import assert_bash_exec, assert_complete, bash_env_saved
5+
from conftest import (
6+
assert_bash_exec,
7+
assert_complete,
8+
bash_env_saved,
9+
prepare_fixture_dir,
10+
)
611

712
LIVE_HOST = "bash_completion"
813

@@ -149,3 +154,22 @@ def test_xfunc_remote_files(self, bash):
149154
"shared/default/foo ",
150155
"shared/default/foo.d/",
151156
]
157+
158+
@pytest.fixture
159+
def tmpdir_mkfifo(self, request, bash):
160+
tmpdir, _, _ = prepare_fixture_dir(request, files=[], dirs=[])
161+
162+
try:
163+
assert_bash_exec(bash, "mkfifo '%s/local_path_1-pipe'" % tmpdir)
164+
except Exception:
165+
pytest.skip(
166+
"The present system does not allow creating a named pipe."
167+
)
168+
169+
return tmpdir
170+
171+
def test_local_path_mark_1(self, bash, tmpdir_mkfifo):
172+
completion = assert_complete(
173+
bash, "scp local_path_1-", cwd=tmpdir_mkfifo
174+
)
175+
assert completion == "pipe"

0 commit comments

Comments
 (0)