From 2aa9df07b948b60e13aa884eacf3ead8d8a9209c Mon Sep 17 00:00:00 2001 From: Janik Kleinhoff Date: Thu, 7 May 2015 15:59:48 +0000 Subject: [PATCH] !wiki: escape the query before building regex --- src/wolfgame.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/wolfgame.py b/src/wolfgame.py index a576f10..6a1023e 100644 --- a/src/wolfgame.py +++ b/src/wolfgame.py @@ -6690,10 +6690,12 @@ def wiki(cli, nick, chan, rest): if not page: cli.notice(nick, "Could not open https://github.com/lykoss/lykos/wiki") return + + query = re.escape(rest.strip()) #look for exact match first, then for a partial match - match = re.search("^##+ ({0})$\r?\n\r?\n^(.*)$".format(rest.strip()), page, re.MULTILINE + re.IGNORECASE) + match = re.search("^##+ ({0})$\r?\n\r?\n^(.*)$".format(query), page, re.MULTILINE + re.IGNORECASE) if not match: - match = re.search("^##+ ({0}.*)$\r?\n\r?\n^(.*)$".format(rest.strip()), page, re.MULTILINE + re.IGNORECASE) + match = re.search("^##+ ({0}.*)$\r?\n\r?\n^(.*)$".format(query), page, re.MULTILINE + re.IGNORECASE) if not match: cli.notice(nick, "Could not find information on that role in https://github.com/lykoss/lykos/wiki") return