Skip to content

fix(scp): Use less escaping for filenames when not needed - #1701

Open
yedayak wants to merge 1 commit into
scop:mainfrom
yedayak:scp-spaces
Open

fix(scp): Use less escaping for filenames when not needed#1701
yedayak wants to merge 1 commit into
scop:mainfrom
yedayak:scp-spaces

Conversation

@yedayak

@yedayak yedayak commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator

fix(scp): Use less escaping for filenames when not needed

OpenSSH 9.0 changed the default protocol the "scp" command uses to
sftp, which needs less escaping for special characters in remote
filenames. Check if the command has the option to use the legacy
protocol and do less escaping.

If the command line has the "-O" option to use the legacy protocol,
we revert to the old behaviour.

The extra escaping is necessary for older versions, so we can't do it
unconditionally.

Fixes: #1540

Comment thread completions-core/ssh.bash
!(*:*)/* | [.~]*) ;; # looks like a path
*:*)
_comp_xfunc_scp_compgen_remote_files
# if scp supports "-O", which forces legacy scp/rcp protocols,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't checked the behavior, but I have a naive question. When the user specifies the -O option to scp, does it change the number of required escapes? In such a case, should we use the legacy quoting even for the newer versions of scp?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, updated PR

OpenSSH 9.0 changed the default protocol the "scp" command uses to
sftp, which needs less escaping for special characters in remote
filenames. Check if the command has the option to use the legacy
protocol and do less escaping.

If the command line has the "-O" option to use the legacy protocol,
we revert to the old behaviour.

The extra escaping is necessary for older versions, so we can't do it
unconditionally.

Fixes: scop#1540
Comment thread test/t/test_scp.py
bash, r"ssh() { printf '%s\n' 'abc def.txt' 'abc\ def.txt'; }"
)
completion = assert_complete(bash, "scp remote_host:abc\\")
completion_legacy_proto = assert_complete(

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't love this, but I think its better than having completely separate tests for -O. Open to other suggestions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

scp: remote filenames get escaped twice

2 participants