From 280751b36e715b006c631ba6c08de99ccc74f6d2 Mon Sep 17 00:00:00 2001 From: mcarton Date: Wed, 28 Oct 2015 15:13:33 +0100 Subject: [PATCH] Fix the unzip rules and filenames with spaces --- tests/rules/test_dirty_unzip.py | 2 ++ thefuck/rules/dirty_unzip.py | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/rules/test_dirty_unzip.py b/tests/rules/test_dirty_unzip.py index d68e936f..9c0b4e51 100644 --- a/tests/rules/test_dirty_unzip.py +++ b/tests/rules/test_dirty_unzip.py @@ -43,6 +43,8 @@ def test_side_effect(zip_error, script): @pytest.mark.parametrize('script,fixed', [ ('unzip foo', 'unzip foo -d foo'), + (R"unzip foo\ bar.zip", R"unzip foo\ bar.zip -d 'foo bar'"), + (R"unzip 'foo bar.zip'", R"unzip 'foo bar.zip' -d 'foo bar'"), ('unzip foo.zip', 'unzip foo.zip -d foo')]) def test_get_new_command(zip_error, script, fixed): assert get_new_command(Command(script=script)) == fixed diff --git a/thefuck/rules/dirty_unzip.py b/thefuck/rules/dirty_unzip.py index d0a1248f..fced9b37 100644 --- a/thefuck/rules/dirty_unzip.py +++ b/thefuck/rules/dirty_unzip.py @@ -1,6 +1,7 @@ import os import zipfile from thefuck.utils import for_app +from thefuck.shells import quote def _is_bad_zip(file): @@ -13,7 +14,7 @@ def _zip_file(command): # unzip [-flags] file[.zip] [file(s) ...] [-x file(s) ...] # ^ ^ files to unzip from the archive # archive to unzip - for c in command.script.split()[1:]: + for c in command.split_script[1:]: if not c.startswith('-'): if c.endswith('.zip'): return c @@ -28,7 +29,7 @@ def match(command): def get_new_command(command): - return '{} -d {}'.format(command.script, _zip_file(command)[:-4]) + return '{} -d {}'.format(command.script, quote(_zip_file(command)[:-4])) def side_effect(old_cmd, command):