Ver código fonte

Improve handling of templates in strange cases.

tags/v0.1
Ben Kurtovic 12 anos atrás
pai
commit
02fe3b0833
2 arquivos alterados com 5 adições e 5 exclusões
  1. +2
    -2
      mwparserfromhell/parser/builder.py
  2. +3
    -3
      mwparserfromhell/parser/tokenizer.py

+ 2
- 2
mwparserfromhell/parser/builder.py Ver arquivo

@@ -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 Ver arquivo

@@ -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


Carregando…
Cancelar
Salvar