1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
# DP: Proposed patch for issue #670664.
--- a/Lib/HTMLParser.py
+++ b/Lib/HTMLParser.py
@@ -96,6 +96,7 @@
self.rawdata = ''
self.lasttag = '???'
self.interesting = interesting_normal
+ self.cdata_tag = None
markupbase.ParserBase.reset(self)
def feed(self, data):
@@ -120,11 +121,13 @@
"""Return full source of start tag: '<...>'."""
return self.__starttag_text
- def set_cdata_mode(self):
+ def set_cdata_mode(self, tag):
self.interesting = interesting_cdata
+ self.cdata_tag = tag.lower()
def clear_cdata_mode(self):
self.interesting = interesting_normal
+ self.cdata_tag = None
# Internal -- handle data as far as reasonable. May leave state
# and data to be processed by a subsequent call. If 'end' is
@@ -270,7 +273,7 @@
else:
self.handle_starttag(tag, attrs)
if tag in self.CDATA_CONTENT_ELEMENTS:
- self.set_cdata_mode()
+ self.set_cdata_mode(tag)
return endpos
# Internal -- check to see if we have a complete starttag; return end
@@ -314,10 +317,16 @@
j = match.end()
match = endtagfind.match(rawdata, i) # </ + tag + >
if not match:
+ if self.cdata_tag is not None: return j
self.error("bad end tag: %r" % (rawdata[i:j],))
- tag = match.group(1)
+ tag = match.group(1).strip()
+
+ if self.cdata_tag is not None:
+ if tag.lower() != self.cdata_tag: return j
+
self.handle_endtag(tag.lower())
self.clear_cdata_mode()
+
return j
# Overridable -- finish processing of start+end tag: <tag.../>
|