From 871d48c688bf8133f886e1d84de7de536e252ae6 Mon Sep 17 00:00:00 2001 From: Ben Kurtovic Date: Thu, 10 Jul 2014 19:20:48 -0400 Subject: [PATCH] Solve a couple more coverage issues; tighten. --- .coveragerc | 1 + mwparserfromhell/parser/tokenizer.py | 8 ++++++-- tests/tokenizer/templates.mwtest | 14 ++++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/.coveragerc b/.coveragerc index 909a0e2..48a64ce 100644 --- a/.coveragerc +++ b/.coveragerc @@ -6,3 +6,4 @@ partial_branches = pragma: no branch if py3k: if not py3k: + if py26: diff --git a/mwparserfromhell/parser/tokenizer.py b/mwparserfromhell/parser/tokenizer.py index 09eb799..d867234 100644 --- a/mwparserfromhell/parser/tokenizer.py +++ b/mwparserfromhell/parser/tokenizer.py @@ -369,9 +369,11 @@ class Tokenizer(object): if "(" in this and ")" in punct: punct = punct[:-1] # ')' is not longer valid punctuation if this.endswith(punct): - for i in reversed(range(-len(this), 0)): - if i == -len(this) or this[i - 1] not in punct: + for i in range(len(this) - 1, 0, -1): + if this[i - 1] not in punct: break + else: + i = 0 stripped = this[:i] if stripped and tail: self._emit_text(tail) @@ -762,6 +764,8 @@ class Tokenizer(object): depth -= 1 if depth == 0: break + else: # pragma: no cover (untestable/exceptional case) + raise ParserError("_handle_single_tag_end() missed a TagCloseOpen") padding = stack[index].padding stack[index] = tokens.TagCloseSelfclose(padding=padding, implicit=True) return self._pop() diff --git a/tests/tokenizer/templates.mwtest b/tests/tokenizer/templates.mwtest index 78d7883..ff8a308 100644 --- a/tests/tokenizer/templates.mwtest +++ b/tests/tokenizer/templates.mwtest @@ -376,6 +376,20 @@ output: [Text(text="{{\nfoo\n|\n{{\nb\nar\n|\nb\naz\n=\nb\niz\n}}\n=\nb\nuzz\n}} --- +name: newlines_spaces +label: newlines in the middle of a template name, followed by spaces +input: "{{foo\n }}" +output: [TemplateOpen(), Text(text="foo\n "), TemplateClose()] + +--- + +name: newlines_spaces_param +label: newlines in the middle of a template name, followed by spaces +input: "{{foo\n }}" +output: [TemplateOpen(), Text(text="foo\n "), TemplateClose()] + +--- + name: invalid_name_left_brace_middle label: invalid characters in template name: left brace in middle input: "{{foo{bar}}"