-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
gh-135462: Fix quadratic complexity in processing special input in HTMLParser #135464
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
gh-135462: Fix quadratic complexity in processing special input in HTMLParser #135464
Conversation
77d5125
to
c87cb49
Compare
The solution has been written in a way that simplifies backporting. There are other issues, and the code will be refactored in new versions after fixing them. |
@support.requires_resource('cpu') | ||
def test_eof_no_quadratic_complexity(self): | ||
# Each of these examples used to take about an hour. | ||
# Now they take a fraction of a second. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If they now take a fraction of a second, is there a reason to require the cpu
resource?
My understanding is that:
- with the
requires_resource('cpu')
decorator:- this test would normally be skipped
- in case of regression, we won't notice unless the
cpu
is enabled
- without the decorator:
- this test is always run and completes quickly
- in case of regression, the test will timeout/fail and expose the problem
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They totally take 1.3 seconds on my computer. All other tests take 0.1-0.2 seconds. It is a waste of time to run it several times for every update of any PR. Some buildbots are slower than my computer.
I think that it is enough to run this test only on the fastests builtbots. We already used requires_resource('cpu')
in similar tests.
('data', '\n<img src="URL>'), | ||
('comment', '/img'), | ||
('endtag', 'html<')]) | ||
('data', '\n')]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that now everything after the first </html>
is ignored (except the \n
). This is technically a change in behavior, which should be fine if the new behavior matches the HTML5 specs, but maybe should be noted in the whatsnew.
There also seem to be other minor changes in behavior that -- if they follow the specs -- might not need to be documented (a generic "Some additional invalid constructs are now handled according to the HTML5 specs." might be enough)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case, a double-quoted attribute value is never closed. This is https://html.spec.whatwg.org/multipage/parsing.html#parse-error-eof-in-tag .
I have update the NEWS entry.
Co-authored-by: Ezio Melotti <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approach seems sensible to me.
Thanks @serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.9, 3.10, 3.11, 3.12, 3.13, 3.14. |
… in HTMLParser (pythonGH-135464) End-of-file errors are now handled according to the HTML5 specs -- comments and declarations are automatically closed, tags are ignored. (cherry picked from commit 6eb6c5d) Co-authored-by: Serhiy Storchaka <[email protected]>
… in HTMLParser (pythonGH-135464) End-of-file errors are now handled according to the HTML5 specs -- comments and declarations are automatically closed, tags are ignored. (cherry picked from commit 6eb6c5d) Co-authored-by: Serhiy Storchaka <[email protected]>
GH-135481 is a backport of this pull request to the 3.14 branch. |
Sorry, @serhiy-storchaka, I could not cleanly backport this to
|
GH-135482 is a backport of this pull request to the 3.13 branch. |
Sorry, @serhiy-storchaka, I could not cleanly backport this to
|
Sorry, @serhiy-storchaka, I could not cleanly backport this to
|
Sorry, @serhiy-storchaka, I could not cleanly backport this to
|
…l input in HTMLParser (pythonGH-135464) End-of-file errors are now handled according to the HTML5 specs -- comments and declarations are automatically closed, tags are ignored. (cherry picked from commit 6eb6c5d) Co-authored-by: Serhiy Storchaka <[email protected]>
GH-135483 is a backport of this pull request to the 3.12 branch. |
…l input in HTMLParser (pythonGH-135464) End-of-file errors are now handled according to the HTML5 specs -- comments and declarations are automatically closed, tags are ignored. (cherry picked from commit 6eb6c5d) Co-authored-by: Serhiy Storchaka <[email protected]>
GH-135484 is a backport of this pull request to the 3.11 branch. |
…l input in HTMLParser (pythonGH-135464) End-of-file errors are now handled according to the HTML5 specs -- comments and declarations are automatically closed, tags are ignored. (cherry picked from commit 6eb6c5d) Co-authored-by: Serhiy Storchaka <[email protected]>
GH-135485 is a backport of this pull request to the 3.10 branch. |
… input in HTMLParser (pythonGH-135464) End-of-file errors are now handled according to the HTML5 specs -- comments and declarations are automatically closed, tags are ignored. (cherry picked from commit 6eb6c5d) Co-authored-by: Serhiy Storchaka <[email protected]>
GH-135486 is a backport of this pull request to the 3.9 branch. |
…t in HTMLParser (GH-135464) (GH-135482) End-of-file errors are now handled according to the HTML5 specs -- comments and declarations are automatically closed, tags are ignored. (cherry picked from commit 6eb6c5d) Co-authored-by: Serhiy Storchaka <[email protected]>
…t in HTMLParser (GH-135464) (GH-135481) End-of-file errors are now handled according to the HTML5 specs -- comments and declarations are automatically closed, tags are ignored. (cherry picked from commit 6eb6c5d) Co-authored-by: Serhiy Storchaka <[email protected]>
Uh oh!
There was an error while loading. Please reload this page.