Fix #2537 (User-defined entities not processed)

This commit is contained in:
Kovid Goyal 2009-07-11 16:57:20 -06:00
parent cc7b7ebff1
commit ff5490e87f

View File

@ -770,7 +770,18 @@ class Manifest(object):
# declarations, which messes up the coesrcing logic # declarations, which messes up the coesrcing logic
idx = data.find('<html') idx = data.find('<html')
if idx > -1: if idx > -1:
pre = data[:idx]
data = data[idx:] data = data[idx:]
if '<!DOCTYPE' in pre:
user_entities = {}
for match in re.finditer(r'<!ENTITY\s+(\S+)\s+([^>]+)', pre):
val = match.group(2)
if val.startswith('"') and val.endswith('"'):
val = val[1:-1]
user_entities[match.group(1)] = val
if user_entities:
pat = re.compile(r'&(%s);'%('|'.join(user_entities.keys())))
data = pat.sub(lambda m:user_entities[m.group(1)], data)
# Try with more & more drastic measures to parse # Try with more & more drastic measures to parse
def first_pass(data): def first_pass(data):