Browse Source

Improve handling of templates in strange cases.

tags/v0.1
Ben Kurtovic 11 years ago
parent
commit
02fe3b0833
2 changed files with 5 additions and 5 deletions
  1. +2
    -2
      mwparserfromhell/parser/builder.py
  2. +3
    -3
      mwparserfromhell/parser/tokenizer.py

+ 2
- 2
mwparserfromhell/parser/builder.py View File

@@ -76,8 +76,8 @@ class Builder(object):
if isinstance(token, tokens.TemplateParamSeparator):
if not params:
name = self._pop()
default = self._wrap(unicode(min(int_key_range - int_keys)))
param = self._handle_parameter(default)
default = unicode(min(int_key_range - int_keys))
param = self._handle_parameter(self._wrap([Text(default)]))
if re.match(r"[1-9][0-9]*$", param.name.strip()):
# We try a more restrictive test for integers than
# try: int(), because "01" as a key will pass through int()


+ 3
- 3
mwparserfromhell/parser/tokenizer.py View File

@@ -107,9 +107,9 @@ class Tokenizer(object):
if self._context & contexts.TEMPLATE_NAME and self._stack:
head = self._stack[-1]
if isinstance(head, tokens.Text):
text, this = head.text, self._read()
if text.strip() and text.endswith("\n") and this != "\n":
raise BadRoute(self._pop())
if head.text.strip() and head.text.endswith("\n"):
if self._read() not in ["|", "=", "\n"]:
raise BadRoute(self._pop())

def _parse_template(self):
reset = self._head


Loading…
Cancel
Save