Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parser blows up on certain malformed HTML content sections #38

fluffy-critter opened this issue Jul 16, 2019 · 0 comments


Copy link

commented Jul 16, 2019

So, this is a bit of a weird one. It seems that when the feed validator is validating the HTML content within a block, it gets tripped up by certain attributes having no value. For example, this minimal reproduction:

<?xml version="1.0" encoding="utf-8”?>
<feed xmlns="">

    <title>Crash the validator</title>
    <link href="" rel="self" />
    <link href="" />

        <title>This feed crashes feedvalidator</title>
        <link href="" rel="alternate" type="text/html" />
        <content type="html"><![CDATA[
            <p>This generates a weird error.</p>
            <div class="images" style><img src="" alt="meow"></div>
            <p>Isn't it strange?</p>

causes an error:

An error occurred while trying to validate this feed.
Possible causes:
• The address may be incorrect. Make sure the address is spelled correctly. Try loading the feed directly in your browser to make sure a feed exists at that address.
• The feed may be temporarily unavailable. The server may be down, or too slow. Try again later.
• The validator may be busted. If the feed exists, the server is fine, and the problem is reproducible, let us know on the feedvalidator-users mailing list.

The element that’s causing the problem is the <div class=“images” style> - removing that causes the validator to work perfectly.

Via the Python REPL I was able to figure out where exactly the code is blowing up; here's a stack trace:

>>> feedvalidator.validateStream(open('/Users/fluffy/Desktop/feed.xml'))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "feedvalidator/", line 164, in validateStream
    validator = _validate(rawdata, firstOccurrenceOnly, loggedEvents, base, encoding, mediaType=mediaType)
  File "feedvalidator/", line 115, in _validate
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xml/sax/", line 110, in parse
    xmlreader.IncrementalParser.parse(self, source)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xml/sax/", line 123, in parse
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xml/sax/", line 213, in feed
    self._parser.Parse(data, isFinal)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xml/sax/", line 365, in end_element_ns
    self._cont_handler.endElementNS(pair, None)
  File "feedvalidator/", line 266, in endElementNS
    handler.endElementNS(name, qname)
  File "feedvalidator/", line 516, in endElementNS
  File "feedvalidator/", line 82, in validate
  File "feedvalidator/", line 736, in validateSafe
    HTMLValidator(value, self)
  File "feedvalidator/", line 257, in __init__
  File "feedvalidator/vendor/", line 169, in feed
  File "feedvalidator/vendor/", line 209, in goahead
    k = self.parse_starttag(i)
  File "feedvalidator/vendor/", line 332, in parse_starttag
    self.handle_starttag(tag, attrs)
  File "feedvalidator/", line 279, in handle_starttag
    for evil in checkStyle(value):
  File "feedvalidator/", line 304, in checkStyle
    if not re.match("""^([:,;#%.\sa-zA-Z0-9!]|\w-\w|'[\s\w]+'|"[\s\w]+"|\([\d,\s]+\))*$""", style):
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/", line 141, in match
    return _compile(pattern, flags).match(string)
TypeError: expected string or buffer

So, it seems that there's some special-casing on the style attribute parser that dies if it gets a None value.

Oddly enough, I couldn't manage to reproduce this issue with a minimal content block like:

<div style></div>

Anyway, finding this error finally gave me a reason to care about fixing PlaidWeb/Publ#226 sooner rather than later. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
1 participant
You can’t perform that action at this time.