mankyd / htmlmin

A configurable HTML Minifier with safety features
https://htmlmin.readthedocs.org/en/latest/
Other
129 stars 41 forks source link

Empty comments results in IndexError #42

Closed RevolutionTech closed 7 years ago

RevolutionTech commented 7 years ago

A comment that is immediately opened and then closed results in IndexError.

>>> minify('<!---->')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/site-packages/htmlmin/main.py", line 98, in minify
    minifier.feed(input)
  File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/HTMLParser.py", line 117, in feed
    self.goahead(0)
  File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/HTMLParser.py", line 165, in goahead
    k = self.parse_comment(i)
  File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/markupbase.py", line 178, in parse_comment
    self.handle_comment(rawdata[i+4: j])
  File "/usr/local/lib/python2.7/site-packages/htmlmin/parser.py", line 281, in handle_comment
    data[1:] if data[0] == '!' else data))
IndexError: string index out of range

For now, I'm working around this issue by replacing those empty comments with <!-- --> before passing it to minify.

mankyd commented 7 years ago

Seems obsolete, at least with recent checkins. A new release will be out soon.