Mercurial > cpython-lru_cache-weakref
diff Lib/HTMLParser.py @ 73608:91163aa3d5b4 2.7
#13358: HTMLParser now calls handle_data only once for each CDATA.
| author | Ezio Melotti <ezio.melotti@gmail.com> |
|---|---|
| date | Fri, 18 Nov 2011 18:00:40 +0200 |
| parents | 3c3009f63700 |
| children | 333e3acf2008 |
line wrap: on
line diff
--- a/Lib/HTMLParser.py Fri Nov 18 17:30:28 2011 +0200 +++ b/Lib/HTMLParser.py Fri Nov 18 18:00:40 2011 +0200 @@ -14,7 +14,6 @@ # Regular expressions used for parsing interesting_normal = re.compile('[&<]') -interesting_cdata = re.compile(r'<(/|\Z)') incomplete = re.compile('&[a-zA-Z#]') entityref = re.compile('&([a-zA-Z][-.a-zA-Z0-9]*)[^a-zA-Z0-9]') @@ -125,8 +124,8 @@ return self.__starttag_text def set_cdata_mode(self, elem): - self.interesting = interesting_cdata self.cdata_elem = elem.lower() + self.interesting = re.compile(r'</\s*%s\s*>' % self.cdata_elem, re.I) def clear_cdata_mode(self): self.interesting = interesting_normal @@ -144,6 +143,8 @@ if match: j = match.start() else: + if self.cdata_elem: + break j = n if i < j: self.handle_data(rawdata[i:j]) i = self.updatepos(i, j) @@ -212,7 +213,7 @@ else: assert 0, "interesting.search() lied" # end while - if end and i < n: + if end and i < n and not self.cdata_elem: self.handle_data(rawdata[i:n]) i = self.updatepos(i, n) self.rawdata = rawdata[i:]
