Skip to content

within(dir) fails now when dir is an empty string or nil #476

@mherold

Description

@mherold

within('') and within(nil) used to work before #453, but now it fails with "Directory does not exist".

I'm not sure whether the new behaviour is intended? It breaks things in other gems which use sshkit, e.g. capistrano-passenger: https://github.com/capistrano/passenger/blob/6dc408ec690d0cbe8c2e9d86c33ad4f7977dfa73/lib/capistrano/tasks/passenger.cap#L13

Example to reproduce:

> require 'sshkit'
> include SSHKit::DSL
> run_locally { within('') { puts(capture(:ls)) } }
SSHKit::Command::Failed (if test ! -d ''; then echo "Directory does not exist ''''" 1>&2; false; fi exit status: 256)
if test ! -d ''; then echo "Directory does not exist ''''" 1>&2; false; fi stdout: Nothing written
if test ! -d ''; then echo "Directory does not exist ''''" 1>&2; false; fi stderr: Directory does not exist ''''

The reason for the behaviour change seems to be that empty strings will also be shellescape'd:

> ''.shellescape
 => "''" 

(within() in /lib/sshkit/backends/abstract.rb)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions