fix: accept either quote character in the XML declaration

This commit is contained in:
randogoth 2026-10-11 20:50:48 +03:00
parent d4b90a3947
commit f54d350216
3 changed files with 18 additions and 2 deletions

View file

@ -41,7 +41,7 @@ A Mews page MUST be a well-formed, valid XHTML-MP 1.2 document that also follows
### 3.1 Prologue and doctype
A Mews page MUST begin with an XML declaration specifying UTF-8, followed by the XHTML-MP 1.2 doctype:
A Mews page MUST begin with an XML declaration specifying UTF-8, followed by the XHTML-MP 1.2 doctype. Either quote character may be used in the declaration, as XML allows:
```xml
<?xml version="1.0" encoding="UTF-8"?>

View file

@ -46,7 +46,12 @@ SIZE_SHOULD = 64 * 1024
SIZE_TOTAL = 320 * 1024
IMAGE_SHOULD = 50 * 1024
XML_DECLARATION = re.compile(rb'^<\?xml version="1\.0" encoding="(?i:UTF-8)"\?>')
# Either quote character, because XML permits both and serialisers differ:
# lxml writes single quotes. Section 3.1 asks for a declaration naming UTF-8,
# and its example is one way of writing that rather than the only way.
XML_DECLARATION = re.compile(
rb"^<\?xml\s+version\s*=\s*([\"'])1\.0\1\s+encoding\s*=\s*([\"'])(?i:UTF-8)\2\s*\?>"
)
DOCTYPE = re.compile(
rb'<!DOCTYPE\s+html\s+PUBLIC\s+"-//WAPFORUM//DTD XHTML Mobile 1\.2//EN"\s+'
rb'"http://www\.openmobilealliance\.org/tech/DTD/xhtml-mobile12\.dtd"\s*>'

View file

@ -34,6 +34,17 @@ def test_rule_failure_maps_to_its_section(fail_page, name, expected):
assert (match[0].section, match[0].level) == (section, level)
def test_either_quote_character_opens_the_declaration(conforming):
"""Serialisers differ: lxml writes single quotes, and XML allows them."""
page = conforming().replace(
b'<?xml version="1.0" encoding="UTF-8"?>',
b"<?xml version='1.0' encoding='UTF-8'?>",
)
report = validate_bytes(page)
assert "xml-declaration" not in [f.code for f in report.findings]
assert report.conforms
def test_entity_declarations_are_refused_before_parsing(fail_page):
"""A page declaring its own entities is rejected without expanding them."""
report = validate_bytes(fail_page("billion-laughs"))