From 08244ff36e9de893ed5f06742a59a1c8cf411dc5 Mon Sep 17 00:00:00 2001 From: Jeremy Fincher Date: Wed, 12 Nov 2003 21:57:21 +0000 Subject: [PATCH] New test and fix for the associated bug. --- src/callbacks.py | 11 +++++------ test/test_callbacks.py | 3 +++ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/callbacks.py b/src/callbacks.py index f4cf3dd8d..c2c75461f 100644 --- a/src/callbacks.py +++ b/src/callbacks.py @@ -155,16 +155,15 @@ class Tokenizer: # These are the characters valid in a token. Everything printable except # double-quote, left-bracket, and right-bracket. validChars = string.ascii.translate(string.ascii, '\x00\r\n \t"[]') + quotes = '"' def __init__(self, tokens=''): # Add a '|' to tokens to have the pipe syntax. self.validChars = self.validChars.translate(string.ascii, tokens) def _handleToken(self, token): - while token and token[0] == '"' and token[-1] == token[0]: - if len(token) > 1: - token = token[1:-1].decode('string_escape') # 2.3+ - else: - break + if token[0] == token[-1] and token[0] in self.quotes: + token = token[1:-1] + token = token.decode('string-escape') return token def _insideBrackets(self, lexer): @@ -185,7 +184,7 @@ class Tokenizer: """Tokenizes a string according to supybot's nested argument format.""" lexer = shlex.shlex(StringIO(s)) lexer.commenters = '' - lexer.quotes = '"' + lexer.quotes = self.quotes lexer.wordchars = self.validChars args = [] ends = [] diff --git a/test/test_callbacks.py b/test/test_callbacks.py index 1db9a3c2a..85c0ad8e2 100644 --- a/test/test_callbacks.py +++ b/test/test_callbacks.py @@ -52,6 +52,9 @@ class TokenizerTestCase(unittest.TestCase): def testDQsWithBackslash(self): self.assertEqual(tokenize('"\\\\"'), ["\\"]) + def testDoubleQuotes(self): + self.assertEqual(tokenize('"\\"foo\\""'), ['"foo"']) + def testSingleWord(self): self.assertEqual(tokenize('foo'), ['foo'])