From 48445e256ac002776ce6ac61a858570224cb6b9f Mon Sep 17 00:00:00 2001 From: James Lu Date: Sat, 10 Sep 2016 17:29:47 -0700 Subject: [PATCH] SedRegex: sanitize against \n\r\t in output --- SedRegex/plugin.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/SedRegex/plugin.py b/SedRegex/plugin.py index 9fdf8fd..79c9eeb 100644 --- a/SedRegex/plugin.py +++ b/SedRegex/plugin.py @@ -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.+?)[:,] )?s(?P[^\w\s])(?P.*?)(?P=delim)" r"(?P.*?)(?:(?P=delim)(?P[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