Skip to content

Commit 457ef04

Browse files
authored
Merge branch 'scop:main' into zizmor-ghactions
2 parents f86921c + 136dd33 commit 457ef04

File tree

4 files changed

+62
-10
lines changed

4 files changed

+62
-10
lines changed

completions/java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,16 @@ _comp_cmd_java__packages()
113113
_comp_cmd_java__find_sourcepath || return 0
114114
local -a sourcepaths=("${REPLY[@]}")
115115

116+
local REPLY
117+
_comp_dequote "$cur" || REPLY=$cur
118+
local cur_val=${REPLY-}
119+
116120
# convert package syntax to path syntax
117-
local cur=${cur//.//}
121+
local cur_val=${cur_val//.//}
118122
# parse each sourcepath element for packages
119123
for i in "${sourcepaths[@]}"; do
120124
if [[ -d $i ]]; then
121-
_comp_expand_glob files '"$i/$cur"*' || continue
125+
_comp_expand_glob files '"$i/$cur_val"*' || continue
122126
_comp_split -la COMPREPLY "$(
123127
command ls -F -d "${files[@]}" 2>/dev/null |
124128
command sed -e 's|^'"$i"'/||'

completions/ssh

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,14 @@ _comp_cmd_scp__path_esc='[][(){}<>"'"'"',:;^&!$=?`\\|[:space:]]'
467467
# "compopt +o nospace" instead, but it would suffix a space to directory names
468468
# unexpectedly.
469469
#
470+
# FIXME: With the current strategy of using "ls -FL", we cannot distinguish the
471+
# filenames that end with one of the type-classifier characters. For example,
472+
# a regular file "pipe|" and a named pipe "pipe" would both produce the
473+
# identical result "pipe|" with "ls -1FL". As a consequence, those characters
474+
# at the end of the filename are removed unexpectedly. To solve this problem,
475+
# we need to give up relying on "ls -1FL". See
476+
# https://github.com/scop/bash-completion/issues/1245
477+
#
470478
# Options:
471479
# -d Only directory names are selected.
472480
# @param $1 escape_replacement - If a non-empty value is specified, special
@@ -530,13 +538,16 @@ _comp_xfunc_scp_compgen_remote_files()
530538
done
531539

532540
# remove backslash escape from the first colon
533-
local cur=${cur/\\:/:}
534-
535-
local _userhost=${cur%%?(\\):*}
536-
local _path=${cur#*:}
541+
local REPLY=$cur
542+
if [[ ! $_less_escaping ]]; then
543+
# unescape (3 backslashes to 1 for chars we escaped)
544+
REPLY=$(command sed -e 's/\\\\\\\('"$_comp_cmd_scp__path_esc"'\)/\\\1/g' <<<"$REPLY")
545+
fi
546+
_comp_dequote "$REPLY"
547+
local cur_val=${REPLY-}
537548

538-
# unescape (3 backslashes to 1 for chars we escaped)
539-
_path=$(command sed -e 's/\\\\\\\('"$_comp_cmd_scp__path_esc"'\)/\\\1/g' <<<"$_path")
549+
local _userhost=${cur_val%%:*}
550+
local _path=${cur_val#*:}
540551

541552
# default to home dir of specified user on remote host
542553
if [[ ! $_path ]]; then
@@ -575,8 +586,12 @@ _comp_xfunc_scp_compgen_local_files()
575586
shift
576587
fi
577588

589+
local REPLY
590+
_comp_dequote "$cur" || REPLY=$cur
591+
local cur_val=${REPLY-}
592+
578593
local files
579-
_comp_expand_glob files '"$cur"*' || return 0
594+
_comp_expand_glob files '"$cur_val"*' || return 0
580595
_comp_compgen -RU files split -l ${1:+-P "$1"} -- "$(
581596
command ls -aF1dL "${files[@]}" 2>/dev/null |
582597
_comp_cmd_scp__escape_path ${_dirs_only:+'-d'}

test/t/test_rsync.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,15 @@ def test_remote_path_with_spaces(self, bash):
7373
completion == r"\ in\ filename.txt"
7474
or completion == r"\\\ in\\\ filename.txt"
7575
)
76+
77+
@pytest.mark.complete(r"rsync -na spaced\ ", cwd="scp")
78+
def test_local_path_with_spaces(self, completion):
79+
"""This function tests xfunc _comp_xfunc_scp_compgen_local_files, which
80+
is defined in completions/ssh, through the rsync interface. We reuse
81+
the fixture directory for the test of the scp completion.
82+
83+
The expected result depends on the rsync version, so we check the
84+
result if it matches either one of two possible expected results.
85+
86+
"""
87+
assert completion == r"\ conf" or completion == r"\\\ conf"

test/t/test_scp.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,13 @@ def test_remote_path_ending_with_backslash(self, bash):
183183

184184
@pytest.fixture
185185
def tmpdir_mkfifo(self, request, bash):
186-
tmpdir, _, _ = prepare_fixture_dir(request, files=[], dirs=[])
186+
# We prepare two files: 1) a named pipe and 2) a regular file ending
187+
# with the same name but an extra special character "|".
188+
tmpdir, _, _ = prepare_fixture_dir(
189+
request,
190+
files=["local_path_2-pipe|"],
191+
dirs=[],
192+
)
187193

188194
# If the system allows creating a named pipe, we create it in a
189195
# temporary directory and returns the path. We cannot check the
@@ -205,3 +211,18 @@ def test_local_path_mark_1(self, bash, tmpdir_mkfifo):
205211
bash, "scp local_path_1-", cwd=tmpdir_mkfifo
206212
)
207213
assert completion == "pipe"
214+
215+
# FIXME: This test currently fails.
216+
# def test_local_path_mark_2(self, bash, tmpdir_mkfifo):
217+
# completion = assert_complete(
218+
# bash, "scp local_path_2-", cwd=tmpdir_mkfifo
219+
# )
220+
# assert completion == "pipe\\|"
221+
222+
@pytest.mark.complete("scp spa", cwd="scp")
223+
def test_local_path_with_spaces_1(self, completion):
224+
assert completion == r"ced\ \ conf"
225+
226+
@pytest.mark.complete(r"scp spaced\ ", cwd="scp")
227+
def test_local_path_with_spaces_2(self, completion):
228+
assert completion == r"\ conf"

0 commit comments

Comments
 (0)