From a735efd0bc4f216b26653378845f1d6795947b48 Mon Sep 17 00:00:00 2001 From: Ben Kurtovic Date: Tue, 21 Aug 2012 23:50:31 -0400 Subject: [PATCH] Template parameters containing newlines should be invalid (closes #6) --- mwparserfromhell/parser/tokenizer.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/mwparserfromhell/parser/tokenizer.py b/mwparserfromhell/parser/tokenizer.py index 8cf6efd..b002c10 100644 --- a/mwparserfromhell/parser/tokenizer.py +++ b/mwparserfromhell/parser/tokenizer.py @@ -149,11 +149,12 @@ class Tokenizer(object): self._write_all(template) self._write(tokens.TemplateClose()) - def _verify_template_name(self): - """Verify that a template's name is valid wikisyntax. + def _verify_no_newlines(self): + """Verify that there are no newlines in the current stack. The route will be failed if the name contains a newline inside of it - (not merely at the beginning or end). + (not merely at the beginning or end). This is used when parsing a + template name or parameter key, which cannot contain newlines. """ self._push_textbuffer() if self._stack: @@ -165,7 +166,7 @@ class Tokenizer(object): def _handle_template_param(self): """Handle a template parameter at the head of the string.""" if self._context & contexts.TEMPLATE_NAME: - self._verify_template_name() + self._verify_no_newlines() self._context ^= contexts.TEMPLATE_NAME if self._context & contexts.TEMPLATE_PARAM_VALUE: self._context ^= contexts.TEMPLATE_PARAM_VALUE @@ -174,6 +175,7 @@ class Tokenizer(object): def _handle_template_param_value(self): """Handle a template parameter's value at the head of the string.""" + self._verify_no_newlines() self._context ^= contexts.TEMPLATE_PARAM_KEY self._context |= contexts.TEMPLATE_PARAM_VALUE self._write(tokens.TemplateParamEquals()) @@ -181,7 +183,7 @@ class Tokenizer(object): def _handle_template_end(self): """Handle the end of the template at the head of the string.""" if self._context & contexts.TEMPLATE_NAME: - self._verify_template_name() + self._verify_no_newlines() self._head += 1 return self._pop()