Skip to content

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

Merged
scop merged 1 commit into
scop:mainfrom
yedayak:scp-spaces
Aug 2, 2026
Merged

fix(scp): Use less escaping for filenames when not needed#1701
scop merged 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
@yedayak
yedayak force-pushed the scp-spaces branch 2 times, most recently from d987ac8 to 39b4830 Compare July 30, 2026 12:56
Comment thread test/t/test_scp.py Outdated

@akinomyoga akinomyoga left a comment

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.

Thank you for updating.

Comment thread completions-core/ssh.bash Outdated
Comment thread test/t/test_scp.py Outdated
Comment thread test/t/test_scp.py Outdated

@scop scop left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Let's also mention remote filenames in the PR title and commit message. I think I'd rephrase it something like "use less remote filename escaping where supported", as the "less ... not needed" reads odd to me.

Comment thread completions-core/ssh.bash
fi
done

if [[ $legacy_scp || ! $("$1" --usage 2>&1) =~ scp\ \[-[^]]*O ]]; then

@scop scop Aug 2, 2026

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I wonder if the logic with $legacy_scp here is the wrong way around.

I'm assuming the intent is to do less escaping if we found -O was given.

So with that, shouldn't we be doing this instead?

Suggested change
if [[ $legacy_scp || ! $("$1" --usage 2>&1) =~ scp\ \[-[^]]*O ]]; then
if [[ ! $legacy_scp && ! $("$1" --usage 2>&1) =~ scp\ \[-[^]]*O ]]; then

...and if logically yes, we could flip the if/else around and remove the negations, so

            if [[ $legacy_scp || $("$1" --usage 2>&1) =~ scp\ \[-[^]]*O ]]; then
                # do the -l here

Also, I find this code with $legacy_scp variable name kind of hard to read, would be better if it had the has_ prefix, but just adding that would kind of make the variable read unclear still. How about something like $has_O_given?

@scop scop Aug 2, 2026

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Er

I'm assuming the intent is to do less escaping if we found -O was given.

...this assumption of mine is false and we want it the other way around, so the original code is fine after all. Will merge with the commit message tweaked.

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
@scop
scop merged commit d6ad3ce into scop:main Aug 2, 2026
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

3 participants