-
Notifications
You must be signed in to change notification settings - Fork 385
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
Fix DOM exception "Not Found Error" when cleaning up after invalid attribute removal #3682
Fix DOM exception "Not Found Error" when cleaning up after invalid attribute removal #3682
Conversation
… are actually all removed
04ee74d
to
88cb213
Compare
Co-Authored-By: Alain Schlesser <[email protected]>
Approved Hi @westonruter, BeforeOn adding Weston's test snippet to a Custom HTML block and saving: <a href=“%E2%80%9Chttps://example.com/path/to/post/%E2%80%9D“ target=“_blank“ rel=“noopener“>Whatever</a> ...there was a fatal error at:
Error log: $ tail -f /path/to/log/php7.2_errors.log
#2 /path/to/wp-content/plugins/amp/includes/sanitizers/class-amp-tag-and-attribute-sanitizer.php(304): AMP_Tag_And_Attribute_Sanitizer->process_node(Object(DOMElement))
#3 /path/to/wp-content/plugins/amp/includes/sanitizers/class-amp-tag-and-attribute-sanitizer.php(287): AMP_Tag_And_Attribute_Sanitizer->sanitize_element(Object(DOMElement))
#4 /path/to/wp-content/plugins/amp/includes/sanitizers/class-amp-tag-and-attribute-sanitizer.php(287): AMP_Tag_And_ in path/to/wp-content/plugins/amp/includes/sanitizers/class-amp-base-sanitizer.php on line 489
[07-Nov-2019 18:13:23 UTC] PHP Fatal error: Uncaught DOMException: Not Found Error in /path/to/wp-content/plugins/amp/includes/sanitizers/class-amp-base-sanitizer.php:489
Stack trace:
#0 /path/to/wp-content/plugins/amp/includes/sanitizers/class-amp-base-sanitizer.php(489): DOMElement->removeAttributeNode(Object(DOMAttr)) There was also an indication of a fatal error in the validator: AfterWith this PR, there was no fatal error. Validation worked as expected, without the message shown above. Also, quickly doing |
…tribute removal (#3682) * Defer cleanup removal of invalid attributes until determining if they are actually all removed * Improve phpdoc comments Co-Authored-By: Alain Schlesser <[email protected]> * Add explanation to check server error log when errors occur
Ah, good idea! |
Testing Steps
<a href=“%E2%80%9Chttps://example.com/path/to/post/%E2%80%9D“ target=“_blank“ rel=“noopener“>Whatever</a>
|
Verified in QA |
Summary
Defer cleanup removal of invalid attributes until determining if they are actually removed. It turns out that calling
\AMP_Base_Sanitizer::clean_up_after_attribute_removal()
inside of\AMP_Base_Sanitizer::remove_invalid_attribute()
can cause subsequent calls to\AMP_Base_Sanitizer::remove_invalid_attribute()
to throw aDOMException
“Not Found Error” if the former removed an attribute that needs to actually be removed by the latter.For example, if there is a
<a href="…" target="…">
element, and bothhref
andtarget
are causing validation errors, then if thetarget
attribute gets cleaned up at the same time ashref
is removed, then whentarget
tries to get removed as well, it will cause an error because it no longer is in the DOM.Fixes issues reported on support forum:
Regression introduced 1.3.0 via #3151.
Checklist