Skip to content

Commit 4213ee2

Browse files
committed
Fix CDATA state when it ends with more than two square brackets.
1 parent faa4953 commit 4213ee2

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

html5lib/tokenizer.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1716,21 +1716,18 @@ def cdataSectionState(self):
17161716
data = []
17171717
while True:
17181718
data.append(self.stream.charsUntil("]"))
1719-
charStack = []
1720-
1721-
for expected in ["]", "]", ">"]:
1722-
charStack.append(self.stream.char())
1723-
matched = True
1724-
if charStack[-1] == EOF:
1725-
data.extend(charStack[:-1])
1726-
break
1727-
elif charStack[-1] != expected:
1728-
matched = False
1729-
data.extend(charStack)
1719+
data.append(self.stream.charsUntil(">"))
1720+
char = self.stream.char()
1721+
if char == EOF:
1722+
break
1723+
else:
1724+
assert char == ">"
1725+
if data[-1][-2:] == "]]":
1726+
data[-1] = data[-1][:-2]
17301727
break
1728+
else:
1729+
data.append(char)
17311730

1732-
if matched:
1733-
break
17341731
data = "".join(data)
17351732
#Deal with null here rather than in the parser
17361733
nullCount = data.count("\u0000")

0 commit comments

Comments
 (0)