瀏覽代碼

Improve handling of templates in strange cases.

tags/v0.1
Ben Kurtovic 12 年之前
父節點
當前提交
02fe3b0833
共有 2 個檔案被更改,包括 5 行新增5 行删除
  1. +2
    -2
      mwparserfromhell/parser/builder.py
  2. +3
    -3
      mwparserfromhell/parser/tokenizer.py

+ 2
- 2
mwparserfromhell/parser/builder.py 查看文件

@@ -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 查看文件

@@ -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…
取消
儲存