From 6e9275da7f5b9a1a99ec9d665eabc5800d0ac0cf Mon Sep 17 00:00:00 2001 From: Denis Kasak Date: Sat, 24 Mar 2018 14:15:41 +0100 Subject: [PATCH] Fix charrefs. Forgot to include # when reconstructing charrefs from their "name". --- matrix/colors.py | 2 +- tests/http_parser_test.py | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/matrix/colors.py b/matrix/colors.py index 6a79b3c..18a2809 100644 --- a/matrix/colors.py +++ b/matrix/colors.py @@ -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: diff --git a/tests/http_parser_test.py b/tests/http_parser_test.py index fba8e2d..3268c10 100644 --- a/tests/http_parser_test.py +++ b/tests/http_parser_test.py @@ -33,6 +33,24 @@ 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('
<faketag>
')