mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 18:24:30 -04:00
Fix explicitly closed <meta charset> tags causing strip_encoding_declarations to result in invalid XML
This commit is contained in:
parent
e35586fd00
commit
84a1eb96fa
@ -11,14 +11,11 @@ import re, codecs
|
||||
|
||||
ENCODING_PATS = [
|
||||
# XML declaration
|
||||
re.compile(r'<\?[^<>]+encoding\s*=\s*[\'"](.*?)[\'"][^<>]*>',
|
||||
re.IGNORECASE),
|
||||
re.compile(r'<\?[^<>]+encoding\s*=\s*[\'"](.*?)[\'"][^<>]*>', re.IGNORECASE),
|
||||
# HTML 4 Pragma directive
|
||||
re.compile(r'''<meta\s+?[^<>]*?content\s*=\s*['"][^'"]*?charset=([-_a-z0-9]+)[^'"]*?['"][^<>]*>''',
|
||||
re.IGNORECASE),
|
||||
re.compile(r'''<meta\s+?[^<>]*?content\s*=\s*['"][^'"]*?charset=([-_a-z0-9]+)[^'"]*?['"][^<>]*>(?:\s*</meta>){0,1}''', re.IGNORECASE),
|
||||
# HTML 5 charset
|
||||
re.compile(r'''<meta\s+charset=['"]([-_a-z0-9]+)['"][^<>]*>''',
|
||||
re.IGNORECASE),
|
||||
re.compile(r'''<meta\s+charset=['"]([-_a-z0-9]+)['"][^<>]*>(?:\s*</meta>){0,1}''', re.IGNORECASE),
|
||||
]
|
||||
ENTITY_PATTERN = re.compile(r'&(\S+?);')
|
||||
|
||||
@ -58,8 +55,7 @@ def force_encoding(raw, verbose, assume_utf8=False):
|
||||
if not encoding:
|
||||
encoding = preferred_encoding
|
||||
encoding = encoding.lower()
|
||||
if _CHARSET_ALIASES.has_key(encoding):
|
||||
encoding = _CHARSET_ALIASES[encoding]
|
||||
encoding = _CHARSET_ALIASES.get(encoding, encoding)
|
||||
if encoding == 'ascii':
|
||||
encoding = 'utf-8'
|
||||
return encoding
|
||||
|
Loading…
x
Reference in New Issue
Block a user