]> granicus.if.org Git - python/commitdiff
bpo-30011: Fixed race condition in HTMLParser.unescape(). (#1140)
authorSerhiy Storchaka <storchaka@gmail.com>
Sat, 15 Apr 2017 15:35:46 +0000 (18:35 +0300)
committerGitHub <noreply@github.com>
Sat, 15 Apr 2017 15:35:46 +0000 (18:35 +0300)
Lib/HTMLParser.py
Misc/NEWS

index 3f97830a9a0d1167e82b4615035eca7e702b7b11..fb9380e128bfc76c838fc6afd427cfd01b54fb6f 100644 (file)
@@ -462,11 +462,12 @@ class HTMLParser(markupbase.ParserBase):
             else:
                 # Cannot use name2codepoint directly, because HTMLParser supports apos,
                 # which is not part of HTML 4
-                import htmlentitydefs
                 if HTMLParser.entitydefs is None:
-                    entitydefs = HTMLParser.entitydefs = {'apos':u"'"}
+                    import htmlentitydefs
+                    entitydefs = {'apos':u"'"}
                     for k, v in htmlentitydefs.name2codepoint.iteritems():
                         entitydefs[k] = unichr(v)
+                    HTMLParser.entitydefs = entitydefs
                 try:
                     return self.entitydefs[s]
                 except KeyError:
index 5f1b64bf769f550a68e444c97d15d6cfdb5c102f..a0908204ee3230cfcbc472b4c82cf3df5ebc1eff 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -42,6 +42,8 @@ Extension Modules
 Library
 -------
 
+- bpo-30011: Fixed race condition in HTMLParser.unescape().
+
 - bpo-30068: _io._IOBase.readlines will check if it's closed first when
   hint is present.