Merge pull request #11 from dkasak/master

Fix charrefs.
This commit is contained in:
poljar 2018-03-24 20:18:11 +01:00 committed by GitHub
commit 508a80e981
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 2 deletions

View file

@ -404,7 +404,7 @@ class MatrixHtmlParser(HTMLParser):
self.text += self.unescape("&{};".format(name))
def handle_charref(self, name):
self.text += self.unescape("&{};".format(name))
self.text += self.unescape("&#{};".format(name))
def get_substrings(self):
if self.text:

View file

@ -33,9 +33,26 @@ def test_html_numeric_reference_parsing(entitydef):
assert parser.unescape('&#{};'.format(num)) == character
@given(sampled_from(html_entities))
def test_html_entityref_reconstruction_from_name(entitydef):
name = entitydef[0]
parser = MatrixHtmlParser()
parser.handle_entityref(name)
s = parser.get_substrings()
assert s[0].text == parser.unescape('&{};'.format(name)) and len(s) == 1
@given(sampled_from(html_entities))
def test_html_charref_reconstruction_from_name(entitydef):
num = entitydef[2]
parser = MatrixHtmlParser()
parser.handle_charref(num)
s = parser.get_substrings()
assert s[0].text == parser.unescape('&#{};'.format(num)) and len(s) == 1
def test_parsing_of_escaped_brackets():
p = MatrixHtmlParser()
p.feed('<pre><code>&lt;faketag&gt;</code></pre>')
s = p.get_substrings()
print(s)
assert s[0].text == '<faketag>' and len(s) == 1