SedRegex: sanitize against \n\r\t in output

From: 48445e256a
This commit is contained in:
James Lu 2016-09-10 17:29:47 -07:00
parent 00f26b0a73
commit c1e2e2b8a6

View File

@ -35,6 +35,7 @@ import supybot.ircmsgs as ircmsgs
import supybot.callbacks as callbacks
import supybot.ircutils as ircutils
import supybot.ircdb as ircdb
import supybot.utils as utils
import re
@ -50,6 +51,9 @@ except ImportError:
SED_REGEX = re.compile(r"^(?:(?P<nick>.+?)[:,] )?s(?P<delim>[^\w\s])(?P<pattern>.*?)(?P=delim)"
r"(?P<replacement>.*?)(?:(?P=delim)(?P<flags>[gi]{0,2}))?$")
# Replace newlines and friends with things like literal "\n" (backslash and "n")
axe_spaces = utils.str.MultipleReplacer({'\n': '\\n', '\t': '\\t', '\r': '\\r'})
class SedRegex(callbacks.PluginRegexp):
"""History replacer using sed-style regex syntax."""
threaded = True
@ -148,6 +152,9 @@ class SedRegex(callbacks.PluginRegexp):
text, count, timeout=0.05)
if action: # If the message was an ACTION, prepend the nick back.
subst = '* %s %s' % (m.nick, subst)
subst = axe_spaces(subst)
irc.reply(_("%s meant to say: %s") %
(messageprefix, subst), prefixNick=False)
return