Skip to content

Commit 000d90e

Browse files
committed
fix(rsync,scp): remove file-type marks from "ls -F" properly
The type-classifier mark for named pipes (|) and sockets (=) were not properly removed. These are escaped by a backslash, so the backslash remains if we only remove the character of the type classifier. In this patch, we remove the backslash altogether for characters that are included in _comp_cmd_scp__path_esc.
1 parent 06b4a68 commit 000d90e

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

completions/ssh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -519,8 +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' \
523-
-e 's/[^/]$/& /g')
522+
command sed -e 's/'"$_comp_cmd_scp__path_esc"'/'"$_escape_replacement"'/g' \
523+
-e 's/[*@]$//g' -e 's/\\[|=]$//g' -e 's/[^/]$/& /g')
524524
fi
525525
_comp_compgen -R split -l -- "$_files"
526526
}
@@ -556,7 +556,8 @@ _comp_xfunc_scp_compgen_local_files()
556556
_comp_compgen -RU files split -l -- "$(
557557
command ls -aF1dL "${files[@]}" 2>/dev/null |
558558
command sed -e "s/$_comp_cmd_scp__path_esc/\\\\&/g" \
559-
-e 's/[*@|=]$//g' -e 's/[^/]$/& /g' -e "s/^/${1-}/"
559+
-e 's/[*@]$//g' -e 's/\\[|=]$//g' \
560+
-e 's/[^/]$/& /g' -e "s/^/${1-}/"
560561
)"
561562
fi
562563
}

test/t/test_scp.py

Lines changed: 26 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,23 @@ 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+
return
169+
170+
return tmpdir
171+
172+
def test_local_path_mark_1(self, bash, tmpdir_mkfifo):
173+
completion = assert_complete(
174+
bash, "scp local_path_1-", cwd=tmpdir_mkfifo
175+
)
176+
assert completion == "pipe"

0 commit comments

Comments
 (0)