Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Get encoding reparsing actually working#241

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
gsnedders merged 3 commits intohtml5lib:masterfromgsnedders:encoding_tests
May 4, 2016
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletionshtml5lib/html5parser.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -89,12 +89,11 @@ def _parse(self, stream, innerHTML=False, container="div",
parser=self, **kwargs)
self.reset()

while True:
try:
self.mainLoop()
break
except ReparseException:
self.reset()
try:
self.mainLoop()
except ReparseException:
self.reset()
self.mainLoop()

def reset(self):
self.tree.reset()
Expand Down
2 changes: 1 addition & 1 deletionhtml5lib/inputstream.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -509,8 +509,8 @@ def changeEncoding(self, newEncoding):
self.charEncoding = (self.charEncoding[0], "certain")
else:
self.rawStream.seek(0)
self.reset()
self.charEncoding = (newEncoding, "certain")
self.reset()
raise ReparseException("Encoding changed from %s to %s" % (self.charEncoding[0], newEncoding))

def detectBOM(self):
Expand Down
22 changes: 22 additions & 0 deletionshtml5lib/tests/test_encoding.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,6 +12,28 @@
from html5lib import HTMLParser, inputstream


def test_basic_prescan_length():
data = "<title>Caf\u00E9</title><!--a--><meta charset='utf-8'>".encode('utf-8')
pad = 1024 - len(data) + 1
data = data.replace(b"-a-", b"-" + (b"a" * pad) + b"-")
assert len(data) == 1024 # Sanity
stream = inputstream.HTMLBinaryInputStream(data, chardet=False)
assert 'utf-8' == stream.charEncoding[0].name


def test_parser_reparse():
data = "<title>Caf\u00E9</title><!--a--><meta charset='utf-8'>".encode('utf-8')
pad = 10240 - len(data) + 1
data = data.replace(b"-a-", b"-" + (b"a" * pad) + b"-")
assert len(data) == 10240 # Sanity
stream = inputstream.HTMLBinaryInputStream(data, chardet=False)
assert 'windows-1252' == stream.charEncoding[0].name
p = HTMLParser(namespaceHTMLElements=False)
doc = p.parse(data, useChardet=False)
assert 'utf-8' == p.documentEncoding
assert doc.find(".//title").text == "Caf\u00E9"


def runParserEncodingTest(data, encoding):
p = HTMLParser()
assert p.documentEncoding is None
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp