classification
Title: Exception in HTMLParser for special JavaScript code
Type: behavior Stage: test needed
Components: Library (Lib) Versions: Python 3.1, Python 2.6
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: ajaksu2, eugine_kosenko, ezio.melotti (3)
Priority: normal Keywords easy

Created on 2007-07-12 19:28 by eugine_kosenko, last changed 2009-11-09 21:53 by ezio.melotti.

Messages (2)
msg32487 - (view) Author: Eugine Kosenko (eugine_kosenko) Date: 2007-07-12 19:28
import HTMLParser

p = HTMLParser.HTMLParser()
p.feed("""
<script>
<!--
bmD.write('</sc'+'ript>');
//-->
</script>
""")

Traceback (most recent call last):
  File "<stdin>", line 4, in ?
  File "/usr/lib/python2.4/HTMLParser.py", line 108, in feed
    self.goahead(0)
  File "/usr/lib/python2.4/HTMLParser.py", line 150, in goahead
    k = self.parse_endtag(i)
  File "/usr/lib/python2.4/HTMLParser.py", line 314, in parse_endtag
    self.error("bad end tag: %r" % (rawdata[i:j],))
  File "/usr/lib/python2.4/HTMLParser.py", line 115, in error
    raise HTMLParseError(message, self.getpos())
HTMLParser.HTMLParseError: bad end tag: "</sc'+'ript>", at line 4, column 12

The JavaScript code is protected via HTML comment, so HTMLParser must skip it entirely, and the parsing must be successfull.

Instead of this, the JavaScript code is parsed as a part of the HTML page, and incorrect end tag is detected. If one move the actual end tag </script> up just after start tag <script>, the code is parsed without errors.

Hence the code seems to be artificial, it is used often in real site counters to prevent the blocking of them.
msg85681 - (view) Author: Daniel Diniz (ajaksu2) Date: 2009-04-07 04:03
Confirmed in trunk, py3k.
History
Date User Action Args
2009-11-09 21:53:16ezio.melottisetnosy: + ezio.melotti
2009-04-22 05:07:32ajaksu2setkeywords: + easy
2009-04-07 04:03:20ajaksu2setversions: + Python 2.6, Python 3.1, - Python 2.4
nosy: + ajaksu2

messages: + msg85681

type: behavior
stage: test needed
2007-07-12 19:28:02eugine_kosenkocreate