mirror of
https://github.com/jlu5/SupyPlugins.git
synced 2025-05-03 08:51:13 -05:00
SedRegex: sanitize against \n\r\t in output
This commit is contained in:
parent
a1439120f5
commit
48445e256a
@ -35,6 +35,7 @@ import supybot.ircmsgs as ircmsgs
|
|||||||
import supybot.callbacks as callbacks
|
import supybot.callbacks as callbacks
|
||||||
import supybot.ircutils as ircutils
|
import supybot.ircutils as ircutils
|
||||||
import supybot.ircdb as ircdb
|
import supybot.ircdb as ircdb
|
||||||
|
import supybot.utils as utils
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
|
||||||
@ -50,6 +51,9 @@ except ImportError:
|
|||||||
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>[gi]{0,2}))?$")
|
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):
|
class SedRegex(callbacks.PluginRegexp):
|
||||||
"""History replacer using sed-style regex syntax."""
|
"""History replacer using sed-style regex syntax."""
|
||||||
threaded = True
|
threaded = True
|
||||||
@ -148,6 +152,9 @@ class SedRegex(callbacks.PluginRegexp):
|
|||||||
text, count, timeout=0.05)
|
text, count, timeout=0.05)
|
||||||
if action: # If the message was an ACTION, prepend the nick back.
|
if action: # If the message was an ACTION, prepend the nick back.
|
||||||
subst = '* %s %s' % (m.nick, subst)
|
subst = '* %s %s' % (m.nick, subst)
|
||||||
|
|
||||||
|
subst = axe_spaces(subst)
|
||||||
|
|
||||||
irc.reply(_("%s meant to say: %s") %
|
irc.reply(_("%s meant to say: %s") %
|
||||||
(messageprefix, subst), prefixNick=False)
|
(messageprefix, subst), prefixNick=False)
|
||||||
return
|
return
|
||||||
|
Loading…
x
Reference in New Issue
Block a user