mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-24 02:54:05 +01:00
SedRegex: Make pattern case-insensitive.
To fixes a mismatch between callbacks, which use flags=re.I by default, and SED_REGEX.search which isn't; so 'S/foo/bar/' errored because it matches case-insensitively so _unpack_sed is entered, but then _unpack_sed fails to match it case-sensitively.
This commit is contained in:
parent
e2d72c5a43
commit
d296bbb949
@ -53,7 +53,8 @@ if sys.version_info[0] < 3:
|
|||||||
'https://github.com/jlu5/SupyPlugins/tree/python2-legacy')
|
'https://github.com/jlu5/SupyPlugins/tree/python2-legacy')
|
||||||
|
|
||||||
SED_REGEX = re.compile(r"^(?:(?P<nick>.+?)[:,] )?s(?P<delim>[^\w\s])(?P<pattern>.*?)(?P=delim)"
|
SED_REGEX = re.compile(r"^(?:(?P<nick>.+?)[:,] )?s(?P<delim>[^\w\s])(?P<pattern>.*?)(?P=delim)"
|
||||||
r"(?P<replacement>.*?)(?P=delim)(?P<flags>[a-z]*)$")
|
r"(?P<replacement>.*?)(?P=delim)(?P<flags>[a-z]*)$",
|
||||||
|
re.I)
|
||||||
|
|
||||||
# Replace newlines and friends with things like literal "\n" (backslash and "n")
|
# Replace newlines and friends with things like literal "\n" (backslash and "n")
|
||||||
axe_spaces = utils.str.MultipleReplacer({'\n': '\\n', '\t': '\\t', '\r': '\\r'})
|
axe_spaces = utils.str.MultipleReplacer({'\n': '\\n', '\t': '\\t', '\r': '\\r'})
|
||||||
@ -85,15 +86,12 @@ class SedRegex(callbacks.PluginRegexp):
|
|||||||
|
|
||||||
match = SED_REGEX.search(escaped_expr)
|
match = SED_REGEX.search(escaped_expr)
|
||||||
|
|
||||||
if not match:
|
|
||||||
return
|
|
||||||
|
|
||||||
groups = match.groupdict()
|
groups = match.groupdict()
|
||||||
pattern = groups['pattern'].replace('\0', delim)
|
pattern = groups['pattern'].replace('\0', delim)
|
||||||
replacement = groups['replacement'].replace('\0', delim)
|
replacement = groups['replacement'].replace('\0', delim)
|
||||||
|
|
||||||
if groups['flags']:
|
if groups['flags']:
|
||||||
raw_flags = set(groups['flags'])
|
raw_flags = set(groups['flags'].lower())
|
||||||
else:
|
else:
|
||||||
raw_flags = set()
|
raw_flags = set()
|
||||||
|
|
||||||
|
@ -51,6 +51,12 @@ class SedRegexTestCase(ChannelPluginTestCase):
|
|||||||
m = self.getMsg(' ')
|
m = self.getMsg(' ')
|
||||||
self.assertIn('Abcd testefgh', str(m))
|
self.assertIn('Abcd testefgh', str(m))
|
||||||
|
|
||||||
|
def testCaseInsensitiveRegexp(self):
|
||||||
|
self.feedMsg('aliens are invading, help!')
|
||||||
|
self.feedMsg('S/a/e/i')
|
||||||
|
m = self.getMsg(' ')
|
||||||
|
self.assertIn('eliens', str(m))
|
||||||
|
|
||||||
def testCaseInsensitiveReplace(self):
|
def testCaseInsensitiveReplace(self):
|
||||||
self.feedMsg('Aliens Are Invading, Help!')
|
self.feedMsg('Aliens Are Invading, Help!')
|
||||||
self.feedMsg('s/a/e/i')
|
self.feedMsg('s/a/e/i')
|
||||||
|
Loading…
Reference in New Issue
Block a user