소스 검색

Fix _handle_single_tag_end()'s token search order (fixes #74)

tags/v0.4
Ben Kurtovic 10 년 전
부모
커밋
0497b54f03
3개의 변경된 파일13개의 추가작업 그리고 4개의 파일을 삭제
  1. +1
    -1
      mwparserfromhell/parser/tokenizer.c
  2. +5
    -3
      mwparserfromhell/parser/tokenizer.py
  3. +7
    -0
      tests/tokenizer/tags.mwtest

+ 1
- 1
mwparserfromhell/parser/tokenizer.c 파일 보기

@@ -1899,7 +1899,7 @@ static PyObject* Tokenizer_handle_single_tag_end(Tokenizer* self)
int is_instance; int is_instance;


len = PyList_GET_SIZE(self->topstack->stack); len = PyList_GET_SIZE(self->topstack->stack);
for (index = 0; index < len; index++) {
for (index = len - 1; index >= 0; index--) {
token = PyList_GET_ITEM(self->topstack->stack, index); token = PyList_GET_ITEM(self->topstack->stack, index);
is_instance = PyObject_IsInstance(token, TagCloseOpen); is_instance = PyObject_IsInstance(token, TagCloseOpen);
if (is_instance == -1) if (is_instance == -1)


+ 5
- 3
mwparserfromhell/parser/tokenizer.py 파일 보기

@@ -21,6 +21,7 @@
# SOFTWARE. # SOFTWARE.


from __future__ import unicode_literals from __future__ import unicode_literals
from itertools import izip
from math import log from math import log
import re import re


@@ -751,11 +752,12 @@ class Tokenizer(object):


def _handle_single_tag_end(self): def _handle_single_tag_end(self):
"""Handle the stream end when inside a single-supporting HTML tag.""" """Handle the stream end when inside a single-supporting HTML tag."""
gen = enumerate(self._stack)
stack = self._stack
gen = izip(xrange(len(stack) - 1, -1, -1), reversed(stack))
index = next(i for i, t in gen if isinstance(t, tokens.TagCloseOpen)) index = next(i for i, t in gen if isinstance(t, tokens.TagCloseOpen))
padding = self._stack[index].padding
padding = stack[index].padding
token = tokens.TagCloseSelfclose(padding=padding, implicit=True) token = tokens.TagCloseSelfclose(padding=padding, implicit=True)
self._stack[index] = token
stack[index] = token
return self._pop() return self._pop()


def _really_parse_tag(self): def _really_parse_tag(self):


+ 7
- 0
tests/tokenizer/tags.mwtest 파일 보기

@@ -124,6 +124,13 @@ output: [TagOpenOpen(), Text(text="ref"), TagAttrStart(pad_first=" ", pad_before


--- ---


name: nested_tag_selfclosing
label: a tag nested within the attributes of another; outer tag implicitly self-closing
input: "<li <b></b></li>"
output: [TagOpenOpen(), Text(text="li"), TagAttrStart(pad_first=" ", pad_before_eq="", pad_after_eq=""), TagOpenOpen(), Text(text="b"), TagCloseOpen(padding=""), TagOpenClose(), Text(text="b"), TagCloseClose(), Text(text="</li"), TagCloseSelfclose(padding="", implicit=True)]

---

name: invalid_space_begin_open name: invalid_space_begin_open
label: invalid tag: a space at the beginning of the open tag label: invalid tag: a space at the beginning of the open tag
input: "< ref>test</ref>" input: "< ref>test</ref>"


불러오는 중...
취소
저장