From 375dbe84273a052acd79c34c5608fe50a4d779b3 Mon Sep 17 00:00:00 2001 From: James Lu Date: Tue, 22 Dec 2015 10:41:42 -0800 Subject: [PATCH] exec: accept newlines and other backslash escapes (in only "exec") This way, more complex code can be entered using newlines: e.g. "for x in range(3):\n irc.reply('hello world')" --- plugins/exec.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/plugins/exec.py b/plugins/exec.py index 3748d92..12dd790 100644 --- a/plugins/exec.py +++ b/plugins/exec.py @@ -12,15 +12,20 @@ import world def _exec(irc, source, args): """ - Admin-only. Executes in the current PyLink instance. + Admin-only. Executes in the current PyLink instance. This command performs backslash escaping of characters, so things like \\n and \\ will work. \x02**WARNING: THIS CAN BE DANGEROUS IF USED IMPROPERLY!**\x02""" utils.checkAuthenticated(irc, source, allowOper=False) - args = ' '.join(args) + + # Allow using \n in the code, while escaping backslashes correctly otherwise. + args = bytes(' '.join(args), 'utf-8').decode("unicode_escape") if not args.strip(): irc.reply('No code entered!') return - log.info('(%s) Executing %r for %s', irc.name, args, utils.getHostmask(irc, source)) + + log.info('(%s) Executing %r for %s', irc.name, args, + utils.getHostmask(irc, source)) exec(args, globals(), locals()) + utils.add_cmd(_exec, 'exec') def _eval(irc, source, args):