@@ -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) | ||||
@@ -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): | ||||
@@ -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>" | ||||