Skip to content

Commit 07b9ff4

Browse files
authored
Fixes error message in case of a non parsable arg_botcomd (errbotio#974)
* Adds a test for arg_botcmd escaping This clarify the behavior for errbotio#950. * Fixed error message in case of incorrect quotation This fixes errbotio#950.
1 parent de1e2f9 commit 07b9ff4

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

errbot/__init__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,16 +339,20 @@ def wrapper(self, mess, args):
339339
# Some clients automatically convert consecutive dashes into a fancy
340340
# hyphen, which breaks long-form arguments. Undo this conversion to
341341
# provide a better user experience.
342-
args = shlex.split(args.replace('—', '--'))
343342
try:
343+
args = shlex.split(args.replace('—', '--'))
344344
parsed_args = err_command_parser.parse_args(args)
345345
except ArgumentParseError as e:
346-
yield "I'm sorry, I couldn't parse that; %s" % e
346+
yield "I'm sorry, I couldn't parse the arguments; %s" % e
347347
yield err_command_parser.format_usage()
348348
return
349349
except HelpRequested:
350350
yield err_command_parser.format_help()
351351
return
352+
except ValueError as ve:
353+
yield "I'm sorry, I couldn't parse this command; %s" % ve
354+
yield err_command_parser.format_help()
355+
return
352356

353357
if unpack_args:
354358
func_args = []

tests/base_backend_test.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,30 @@ def test_arg_botcmd_returns_first_name_last_name(dummy_backend):
470470
assert "%s %s" % (first_name, last_name) == dummy_backend.pop_message().body
471471

472472

473+
def test_arg_botcmd_returns_with_escaping(dummy_backend):
474+
first_name = 'Err\\"'
475+
last_name = 'Bot'
476+
dummy_backend.callback_message(
477+
makemessage(
478+
dummy_backend,
479+
"!returns_first_name_last_name --first-name=%s --last-name=%s" % (first_name, last_name)
480+
)
481+
)
482+
assert 'Err" Bot' == dummy_backend.pop_message().body
483+
484+
485+
def test_arg_botcmd_returns_with_incorrect_escaping(dummy_backend):
486+
first_name = 'Err"'
487+
last_name = 'Bot'
488+
dummy_backend.callback_message(
489+
makemessage(
490+
dummy_backend,
491+
"!returns_first_name_last_name --first-name=%s --last-name=%s" % (first_name, last_name)
492+
)
493+
)
494+
assert 'I couldn\'t parse this command; No closing quotation' in dummy_backend.pop_message().body
495+
496+
473497
def test_arg_botcmd_yields_first_name_last_name(dummy_backend):
474498
first_name = 'Err'
475499
last_name = 'Bot'
@@ -497,7 +521,7 @@ def test_arg_botcmd_doesnt_raise_systemerror(dummy_backend):
497521

498522
def test_arg_botcdm_returns_errors_as_chat(dummy_backend):
499523
dummy_backend.callback_message(makemessage(dummy_backend, "!returns_first_name_last_name --invalid-parameter"))
500-
assert "I'm sorry, I couldn't parse that; unrecognized arguments: --invalid-parameter" \
524+
assert "I couldn't parse the arguments; unrecognized arguments: --invalid-parameter" \
501525
in dummy_backend.pop_message().body
502526

503527

0 commit comments

Comments
 (0)