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

@ -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*>'