diff --git a/CHANGELOG.md b/CHANGELOG.md index f9260a7..69f0d4f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## [Unreleased] +* Temporarily suspend PHP Warnings on invalid tags when processing Gist HTML ([#81](https://github.com/bradyvercher/gistpress/issues/81)) + ## [v3.0.2] - 2020-01-16 * Sanitized the `id` attribute passed to the `[gist]` shortcode. This fixes an XSS vulnerability that could be exploited by untrusted contributors on multi-author sites. Thanks to [@cornerpirate](https://github.com/cornerpirate) for disclosing responsibly. diff --git a/includes/class-gistpress.php b/includes/class-gistpress.php index c92acba..b86b5f1 100644 --- a/includes/class-gistpress.php +++ b/includes/class-gistpress.php @@ -463,6 +463,10 @@ public function process_gist_html( $html, array $args ) { $html = '' . $html; $dom = new DOMDocument(); + + // Temporarily suppress warnings for invalid tags. + $previous_libxml_use_internal_errors_value = libxml_use_internal_errors( true ); + $dom->loadHTML( $html, LIBXML_HTML_NODEFDTD | LIBXML_HTML_NOIMPLIED ); $lines = $dom->getElementsByTagName( 'tr' ); @@ -537,6 +541,9 @@ public function process_gist_html( $html, array $args ) { $html = $this->process_gist_line_numbers( $html, $args['lines'], $args['lines_start'] ); } + // Reset to previous value. + libxml_use_internal_errors( $previous_libxml_use_internal_errors_value ); + return $html; }