Skip to content

Commit 3227068

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 7d3fe02 commit 3227068

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
@@ -3,7 +3,12 @@
33

44
import pytest
55

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

813
LIVE_HOST = os.environ.get(
914
"BASH_COMPLETION_TEST_LIVE_SSH_HOST", default="bash_completion"
@@ -152,3 +157,22 @@ def test_xfunc_remote_files(self, bash):
152157
"shared/default/foo ",
153158
"shared/default/foo.d/",
154159
]
160+
161+
@pytest.fixture
162+
def tmpdir_mkfifo(self, request, bash):
163+
tmpdir, _, _ = prepare_fixture_dir(request, files=[], dirs=[])
164+
165+
try:
166+
assert_bash_exec(bash, "mkfifo '%s/local_path_1-pipe'" % tmpdir)
167+
except Exception:
168+
pytest.skip(
169+
"The present system does not allow creating a named pipe."
170+
)
171+
172+
return tmpdir
173+
174+
def test_local_path_mark_1(self, bash, tmpdir_mkfifo):
175+
completion = assert_complete(
176+
bash, "scp local_path_1-", cwd=tmpdir_mkfifo
177+
)
178+
assert completion == "pipe"

0 commit comments

Comments
 (0)