From 44c06c483ef779a56d3de2899264cf1355e456e4 Mon Sep 17 00:00:00 2001 From: Pablo Santiago Blum de Aguiar Date: Wed, 20 May 2015 13:35:31 -0300 Subject: [PATCH] fix(whois): check if there's at least one argument to `whois` This avoids thefuck failing when there's no arguments. It fails with: ``` ... File "thefuck/rules/whois.py", line 26, in get_new_command url = command.script.split()[1] IndexError: list index out of range ``` Signed-off-by: Pablo Santiago Blum de Aguiar --- tests/rules/test_whois.py | 4 ++++ thefuck/rules/whois.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/rules/test_whois.py b/tests/rules/test_whois.py index b911106e..18548ce5 100644 --- a/tests/rules/test_whois.py +++ b/tests/rules/test_whois.py @@ -11,6 +11,10 @@ def test_match(command): assert match(command, None) +def test_not_match(): + assert not match(Command(script='whois'), None) + + @pytest.mark.parametrize('command, new_command', [ (Command('whois https://en.wikipedia.org/wiki/Main_Page'), 'whois en.wikipedia.org'), (Command('whois https://en.wikipedia.org/'), 'whois en.wikipedia.org'), diff --git a/thefuck/rules/whois.py b/thefuck/rules/whois.py index f53cdde8..d27ecc16 100644 --- a/thefuck/rules/whois.py +++ b/thefuck/rules/whois.py @@ -19,7 +19,7 @@ def match(command, settings): - www.google.fr → subdomain: www, domain: 'google.fr'; - google.co.uk → subdomain: None, domain; 'google.co.uk'. """ - return 'whois' in command.script + return 'whois' in command.script and len(command.script.split()) > 1 def get_new_command(command, settings):