| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -23,16 +23,16 @@ | |||
| 23 | 23 | starttagopen = re.compile('<[a-zA-Z]') | |
| 24 | 24 | piclose = re.compile('>') | |
| 25 | 25 | commentclose = re.compile(r'--\s*>') | |
| 26 | - tagfind = re.compile('([a-zA-Z][-.a-zA-Z0-9:_]*)(?:\s|/(?!>))*') | ||
| 27 | - # see http://www.w3.org/TR/html5/tokenization.html#tag-open-state | ||
| 28 | - # and http://www.w3.org/TR/html5/tokenization.html#tag-name-state | ||
| 29 | - tagfind_tolerant = re.compile('[a-zA-Z][^\t\n\r\f />\x00]*') | ||
| 30 | 26 | # Note: | |
| 31 | 27 | # 1) the strict attrfind isn't really strict, but we can't make it | |
| 32 | 28 | # correctly strict without breaking backward compatibility; | |
| 33 | - # 2) if you change attrfind remember to update locatestarttagend too; | ||
| 34 | - # 3) if you change attrfind and/or locatestarttagend the parser will | ||
| 29 | + # 2) if you change tagfind/attrfind remember to update locatestarttagend too; | ||
| 30 | + # 3) if you change tagfind/attrfind and/or locatestarttagend the parser will | ||
| 35 | 31 | # explode, so don't do it. | |
| 32 | + tagfind = re.compile('([a-zA-Z][-.a-zA-Z0-9:_]*)(?:\s|/(?!>))*') | ||
| 33 | + # see http://www.w3.org/TR/html5/tokenization.html#tag-open-state | ||
| 34 | + # and http://www.w3.org/TR/html5/tokenization.html#tag-name-state | ||
| 35 | + tagfind_tolerant = re.compile('([a-zA-Z][^\t\n\r\f />\x00]*)(?:\s|/(?!>))*') | ||
| 36 | 36 | attrfind = re.compile( | |
| 37 | 37 | r'\s*([a-zA-Z_][-.:a-zA-Z_0-9]*)(\s*=\s*' | |
| 38 | 38 | r'(\'[^\']*\'|"[^"]*"|[^\s"\'=<>`]*))?') | |
@@ -54,7 +54,7 @@ | |||
| 54 | 54 | \s* # trailing whitespace | |
| 55 | 55 | """, re.VERBOSE) | |
| 56 | 56 | locatestarttagend_tolerant = re.compile(r""" | |
| 57 | - <[a-zA-Z][-.a-zA-Z0-9:_]* # tag name | ||
| 57 | + <[a-zA-Z][^\t\n\r\f />\x00]* # tag name | ||
| 58 | 58 | (?:[\s/]* # optional whitespace before attribute name | |
| 59 | 59 | (?:(?<=['"\s/])[^\s/>][^\s/=>]* # attribute name | |
| 60 | 60 | (?:\s*=+\s* # value indicator | |
@@ -328,7 +328,10 @@ def parse_starttag(self, i): | |||
| 328 | 328 | ||
| 329 | 329 | # Now parse the data between i+1 and j into a tag and attrs | |
| 330 | 330 | attrs = [] | |
| 331 | - match = tagfind.match(rawdata, i+1) | ||
| 331 | + if self.strict: | ||
| 332 | + match = tagfind.match(rawdata, i+1) | ||
| 333 | + else: | ||
| 334 | + match = tagfind_tolerant.match(rawdata, i+1) | ||
| 332 | 335 | assert match, 'unexpected call to parse_starttag()' | |
| 333 | 336 | k = match.end() | |
| 334 | 337 | self.lasttag = tag = match.group(1).lower() | |
@@ -440,7 +443,7 @@ def parse_endtag(self, i): | |||
| 440 | 443 | return i+3 | |
| 441 | 444 | else: | |
| 442 | 445 | return self.parse_bogus_comment(i) | |
| 443 | - tagname = namematch.group().lower() | ||
| 446 | + tagname = namematch.group(1).lower() | ||
| 444 | 447 | # consume and ignore other stuff between the name and the > | |
| 445 | 448 | # Note: this is not 100% correct, since we might have things like | |
| 446 | 449 | # </tag attr=">">, but looking for > after tha name should cover | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -229,6 +229,11 @@ def test_starttag_junk_chars(self): | |||
| 229 | 229 | self._parse_error("<a foo='bar") | |
| 230 | 230 | self._parse_error("<a foo='>'") | |
| 231 | 231 | self._parse_error("<a foo='>") | |
| 232 | + self._parse_error("<a$>") | ||
| 233 | + self._parse_error("<a$b>") | ||
| 234 | + self._parse_error("<a$b/>") | ||
| 235 | + self._parse_error("<a$b >") | ||
| 236 | + self._parse_error("<a$b />") | ||
| 232 | 237 | ||
| 233 | 238 | def test_valid_doctypes(self): | |
| 234 | 239 | # from http://www.w3.org/QA/2002/04/valid-dtd-list.html | |
@@ -368,8 +373,8 @@ def test_tolerant_parsing(self): | |||
| 368 | 373 | ('starttag', 'html', [('<html', None)]), | |
| 369 | 374 | ('data', 'te>>xt'), | |
| 370 | 375 | ('entityref', 'a'), | |
| 371 | - ('data', '<<bc'), | ||
| 372 | - ('endtag', 'a'), | ||
| 376 | + ('data', '<'), | ||
| 377 | + ('starttag', 'bc<', [('a', None)]), | ||
| 373 | 378 | ('endtag', 'html'), | |
| 374 | 379 | ('data', '\n<img src="URL>'), | |
| 375 | 380 | ('comment', '/img'), | |
@@ -380,15 +385,19 @@ def test_starttag_junk_chars(self): | |||
| 380 | 385 | self._run_check("</$>", [('comment', '$')]) | |
| 381 | 386 | self._run_check("</", [('data', '</')]) | |
| 382 | 387 | self._run_check("</a", [('data', '</a')]) | |
| 383 | - # XXX this might be wrong | ||
| 384 | - self._run_check("<a<a>", [('data', '<a'), ('starttag', 'a', [])]) | ||
| 388 | + self._run_check("<a<a>", [('starttag', 'a<a', [])]) | ||
| 385 | 389 | self._run_check("</a<a>", [('endtag', 'a<a')]) | |
| 386 | 390 | self._run_check("<!", [('data', '<!')]) | |
| 387 | 391 | self._run_check("<a", [('data', '<a')]) | |
| 388 | 392 | self._run_check("<a foo='bar'", [('data', "<a foo='bar'")]) | |
| 389 | 393 | self._run_check("<a foo='bar", [('data', "<a foo='bar")]) | |
| 390 | 394 | self._run_check("<a foo='>'", [('data', "<a foo='>'")]) | |
| 391 | 395 | self._run_check("<a foo='>", [('data', "<a foo='>")]) | |
| 396 | + self._run_check("<a$>", [('starttag', 'a$', [])]) | ||
| 397 | + self._run_check("<a$b>", [('starttag', 'a$b', [])]) | ||
| 398 | + self._run_check("<a$b/>", [('startendtag', 'a$b', [])]) | ||
| 399 | + self._run_check("<a$b >", [('starttag', 'a$b', [])]) | ||
| 400 | + self._run_check("<a$b />", [('startendtag', 'a$b', [])]) | ||
| 392 | 401 | ||
| 393 | 402 | def test_slashes_in_starttag(self): | |
| 394 | 403 | self._run_check('<a foo="var"/>', [('startendtag', 'a', [('foo', 'var')])]) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,6 +13,9 @@ Core and Builtins | |||
| 13 | 13 | Library | |
| 14 | 14 | ------- | |
| 15 | 15 | ||
| 16 | + - Issue #19480: HTMLParser now accepts all valid start-tag names as defined | ||
| 17 | + by the HTML5 standard. | ||
| 18 | + | ||
| 16 | 19 | - Issue #6157: Fixed tkinter.Text.debug(). Original patch by Guilherme Polo. | |
| 17 | 20 | ||
| 18 | 21 | - Issue #6160: The bbox() method of tkinter.Spinbox now returns a tuple of | |
| Back | FazBrowse Home | New Git URL |
0 commit comments