|
25 | 25 |
|
26 | 26 |
|
27 | 27 | # libxml2 sends numeric references in the c1 range through the cp1252 table from 2.14 on, |
28 | | -# where its html tokenizer became html5 conforming. older builds keep the raw character, and |
29 | | -# some wheels still ship one, so the tests below pin whichever applies. |
30 | | -C1_REFERENCES_REMAPPED = etree.LIBXML_VERSION >= (2, 14) |
| 28 | +# where its html tokenizer became html5 conforming. older builds keep the raw character and |
| 29 | +# some wheels still ship one, so the tests that need the mapping do not run there. |
| 30 | +needs_c1_remapping = pytest.mark.skipif( |
| 31 | + etree.LIBXML_VERSION < (2, 14), |
| 32 | + reason=f"libxml2 {etree.LIBXML_VERSION} does not map c1 character references, needs 2.14", |
| 33 | +) |
31 | 34 |
|
32 | 35 |
|
33 | 36 | class TestSelector: |
@@ -858,29 +861,26 @@ def test_xml_entity_expansion(self) -> None: |
858 | 861 |
|
859 | 862 | assert sel.extract() == "<foo>&xxe;</foo>" |
860 | 863 |
|
| 864 | + @needs_c1_remapping |
861 | 865 | def test_html_c1_character_references(self) -> None: |
862 | 866 | """HTML maps numeric references in the C1 range through the CP1252 table. |
863 | 867 |
|
864 | 868 | ``…`` is an ellipsis rather than U+0085, which is what browsers show |
865 | 869 | and what the HTML standard requires. ``html.unescape`` implements the same |
866 | 870 | table, so it is used as the reference. See #76. |
867 | | -
|
868 | | - On a libxml2 older than 2.14 the reference comes back as the raw character |
869 | | - instead, which is the behaviour the report describes. |
870 | 871 | """ |
871 | 872 | for code_point in range(0x80, 0xA0): |
872 | 873 | reference = f"&#{code_point};" |
873 | | - if C1_REFERENCES_REMAPPED: |
874 | | - expected = html.unescape(reference) |
875 | | - else: |
876 | | - expected = chr(code_point) |
| 874 | + expected = html.unescape(reference) |
877 | 875 | sel = self.sscls(text=f"<p>{reference}</p>") |
878 | 876 | assert sel.css("p::text").get() == expected, reference |
879 | 877 | assert sel.xpath("//p/text()").get() == expected, reference |
880 | 878 |
|
881 | | - def test_html_c1_character_references_hex_and_named(self) -> None: |
882 | | - expected = "\u2026" if C1_REFERENCES_REMAPPED else "\x85" |
883 | | - assert self.sscls(text="<p>…</p>").css("p::text").get() == expected |
| 879 | + @needs_c1_remapping |
| 880 | + def test_html_c1_character_reference_hex(self) -> None: |
| 881 | + assert self.sscls(text="<p>…</p>").css("p::text").get() == "\u2026" |
| 882 | + |
| 883 | + def test_html_named_character_reference(self) -> None: |
884 | 884 | # a named reference does not go through the c1 table, so it is the same everywhere |
885 | 885 | assert self.sscls(text="<p>…</p>").css("p::text").get() == "\u2026" |
886 | 886 |
|
|
0 commit comments