commands._getRe: Restore original args for any failure

String.re uses first('regexpMatcher', 'regexpReplacer').  If the args
provided to String.re are not a matcher and are longer than a single IRC
message (e.g., from a nested command), then regexpReplacer would never
be tried.  A too long error should be handled the same as running out of
args while trying to find a valid regexp.

Signed-off-by: James McCoy <vega.james@gmail.com>
This commit is contained in:
James McCoy 2015-02-18 21:35:57 -05:00
parent b99ff28e33
commit a8cd99f121
2 changed files with 8 additions and 3 deletions

View File

@ -1,6 +1,6 @@
### ###
# Copyright (c) 2002-2005, Jeremiah Fincher # Copyright (c) 2002-2005, Jeremiah Fincher
# Copyright (c) 2009-2010, James McCoy # Copyright (c) 2009-2010,2015, James McCoy
# All rights reserved. # All rights reserved.
# #
# Redistribution and use in source and binary forms, with or without # Redistribution and use in source and binary forms, with or without
@ -375,8 +375,8 @@ def _getRe(f):
else: else:
state.args.append(s) state.args.append(s)
else: else:
state.errorInvalid('regular expression', s) raise ValueError
except IndexError: except (ValueError, IndexError):
args[:] = original args[:] = original
state.errorInvalid('regular expression', s) state.errorInvalid('regular expression', s)
return get return get

View File

@ -1,5 +1,6 @@
### ###
# Copyright (c) 2002-2005, Jeremiah Fincher # Copyright (c) 2002-2005, Jeremiah Fincher
# Copyright (c) 2015, James McCoy
# All rights reserved. # All rights reserved.
# #
# Redistribution and use in source and binary forms, with or without # Redistribution and use in source and binary forms, with or without
@ -181,5 +182,9 @@ class FirstTestCase(CommandsTestCase):
self.assertStateErrored([first('int', 'something')], ['words'], self.assertStateErrored([first('int', 'something')], ['words'],
errored=False) errored=False)
def testLongRegexp(self):
spec = [first('regexpMatcher', 'regexpReplacer'), 'text']
self.assertStateErrored(spec, ['s/foo/bar/', 'x' * 512], errored=False)
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: # vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: