Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Globing remote path fails on pattern with spaces #322

Closed
asmfreak opened this issue May 25, 2017 · 3 comments · Fixed by #323
Closed

Globing remote path fails on pattern with spaces #322

asmfreak opened this issue May 25, 2017 · 3 comments · Fixed by #323

Comments

@asmfreak
Copy link
Contributor

asmfreak commented May 25, 2017

Hi!
When you glob a file and pattern contain spaces it returns nonexistent files

num=42
rem = SshMachine('host', user='user')
dir = rem.path( '/some/dir/with_no_spaces/')
files = dir // ('spaces №{}'.format(num))
print(files)

yields this:

[<RemotePath /some/dir/with_no_spaces/spaces>, <RemotePath /home/user/№42>]

I've searched the repo and the problem seems in this line. It seems that there is no escaping going on.
I would have fixed that, but I don't know how does escaping works.

@henryiii
Copy link
Collaborator

henryiii commented May 25, 2017

Step one: make a test:

    @skip_on_windows
    def test_glob_spaces(self):
        fileloc = local.cwd / 'file with space.txt'
        assert fileloc.exists()

        assert local.cwd // "*space.txt"
        assert local.cwd // "file with*"

(Ignore my incorrect comment earlier)

Okay, now the remote test:

     def test_glob_spaces(self):
         with self._connect() as rem:
             with rem.cwd(os.path.dirname(os.path.abspath(__file__))):
                 filenames = [f.name for f in rem.cwd // ("*space.txt")]
                 assert "file with space.txt" in filenames
 
                 filenames = [f.name for f in rem.cwd // ("*with space.txt")]
                 assert "file with space.txt" in filenames # fails

@asmfreak
Copy link
Contributor Author

asmfreak commented May 25, 2017

Wow! That was fast! Maybe more tests? 👍

In [7]: def test_glob_spaces():
   ...:     fileloc = remote.cwd / '$fde33.txt'
   ...:     assert fileloc.exists()
   ...:     
   ...:     assert local.cwd // "*33.txt"
   ...:     assert local.cwd // "$*"
   ...: test_glob_spaces()
   ...: 
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-7-256c51189937> in <module>()
      5     assert local.cwd // "*33.txt"
      6     assert local.cwd // "$*"
----> 7 test_glob_spaces()

<ipython-input-7-256c51189937> in test_glob_spaces()
      3     assert fileloc.exists()
      4 
----> 5     assert local.cwd // "*33.txt"
      6     assert local.cwd // "$*"
      7 test_glob_spaces()

AssertionError: 

@henryiii
Copy link
Collaborator

henryiii commented Jun 5, 2017

You could fix that one if you want; I'm not too worried about it since a filename with a $ is a pain in bash anyway.

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 a pull request may close this issue.

2 participants