Parcourir la source

Improve handling of templates in strange cases.

tags/v0.1
Ben Kurtovic il y a 12 ans
Parent
révision
02fe3b0833
2 fichiers modifiés avec 5 ajouts et 5 suppressions
  1. +2
    -2
      mwparserfromhell/parser/builder.py
  2. +3
    -3
      mwparserfromhell/parser/tokenizer.py

+ 2
- 2
mwparserfromhell/parser/builder.py Voir le fichier

@@ -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 Voir le fichier

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


Chargement…
Annuler
Enregistrer