[issue41748] HTMLParser: comma in attribute values with/without space

Ezio Melotti report at bugs.python.org
Sun Jan 3 03:49:49 EST 2021


Ezio Melotti <ezio.melotti at gmail.com> added the comment:

Writing tests that verify the expected behavior is a great first step. The expected output in the tests should match the behavior described by the HTML 5 specs (which should also correspond to the browsers' behavior), and should initially fail. You can start creating a PR with only the tests, clarifying that it's a work in progress, or wait until you have the fix too.

The next step would be tweaking the regex and the code until both the new tests and all the other ones work (excluding the one with the commas you are fixing).  You can then commit the fix in the same branch and push it -- GitHub will automatically update the PR.


> Do you have a suggestion to fix it?

If you are familiar enough with regexes, you could try to figure out whether it matches the invalid attributes or not, and if not why (I took a quick look and I didn't see anything immediately wrong in the regexes).

Since the output of the failing test is [('data', '<div class=bar ,baz=asd>')], it's likely that the parser doesn't know how to handle it and passes it to one of the handle_data() in the goahead() method.  You can figure out which one is being called and see which are the if-conditions that are leading the interpreter down this path rather than the usual path where the attributes are parsed correctly.

If you have other questions let me know :)

----------
type: crash -> behavior

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue41748>
_______________________________________


More information about the Python-bugs-list mailing list