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

Use internal libxml errors instead of @suppression #24677

Merged
merged 2 commits into from
Sep 1, 2020

Conversation

lsl
Copy link
Contributor

@lsl lsl commented Aug 20, 2020

Description

Instead of using @ to suppress errors during DOMDocument::loadHTML
use libxml_use_internal_errors to capture and suppress the errors
instead.

If there is a custom set_error_handler set for your installation it
will continue to receive warnings and html validation errors from this
loadHTML call. If the goal is to suppress these errors we should try
to capture and drop these without polluting customized error logs.

How has this been tested?

  • Added a unit test to capture errors that would be missed by @ suppression
  • Removed the change and confirmed the test fails
  • Watched the php error log of a test site using the latest posts block with the block setting of "Show post date" toggled on.

Types of changes

Bug fix, there shouldn't be any breaking changes although some people may see less errors for broken block html or html5 features passing through this code.

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR.

Instead of using `@` to suppress errors during `DOMDocument::loadHTML`
use `libxml_use_internal_errors` to capture and suppress the errors
instead.

If there is a custom `set_error_handler` set for your installation it
will continue to receive warnings and html validation errors from this
`loadHTML` call. If the goal is to suppress these errors we should try
to capture and drop these without polluting customized error logs.
@lsl
Copy link
Contributor Author

lsl commented Aug 20, 2020

@ockham may want to take a look at this too - I'm not totally sure what the original suppression was for but I'm hoping this is capturing all those same errors.

}
);

// HTML5 elemetns like <time> are not supported by the DOMDocument parser used by the block supports feature.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// HTML5 elemetns like <time> are not supported by the DOMDocument parser used by the block supports feature.
// HTML5 elements like <time> are not supported by the DOMDocument parser used by the block supports feature.

Copy link
Contributor

@ockham ockham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good, thanks for the fix! One typo, otherwise good to merge (once GH Actions go all green).

@lsl
Copy link
Contributor Author

lsl commented Sep 1, 2020

Reminder: I don't have merge rights here.

@ockham ockham merged commit 33c83fa into WordPress:master Sep 1, 2020
@github-actions github-actions bot added this to the Gutenberg 9.0 milestone Sep 1, 2020
@ockham
Copy link
Contributor

ockham commented Sep 1, 2020

Merged. Thanks again @lsl!

@jorgefilipecosta @youknowriad @mcsf Can we maybe include this in 8.9? These warnings can otherwise clutter warning logs (or the frontend, if WP_DEBUG is true).

@lsl lsl deleted the update/libxml-errors branch September 2, 2020 00:49
@ZebulanStanphill ZebulanStanphill added the [Type] Code Quality Issues or PRs that relate to code quality label Sep 2, 2020
jorgefilipecosta pushed a commit that referenced this pull request Sep 2, 2020
Instead of using `@` to suppress errors during `DOMDocument::loadHTML`, use `libxml_use_internal_errors` to capture and suppress the errors instead.

If there is a custom `set_error_handler` set for your installation, it will continue to receive warnings and html validation errors from this `loadHTML` call. If the goal is to suppress these errors we should try to capture and drop these without polluting customized error logs.
@youknowriad
Copy link
Contributor

Seems like all warnings are not suppressed yet https://wordpress.org/support/topic/warning-a-non-numeric-value-encountered-31/#post-13357203

I wonder if we should try to avoid DOMDocument and just use Regex to include the classes and styles like explored here https://github.com/WordPress/gutenberg/pull/21420/files#diff-4339a9e86722fd029c231f3fb65f0ad2R394-R412

@mcsf mcsf mentioned this pull request Oct 14, 2020
11 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Code Quality Issues or PRs that relate to code quality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants