Skip to content

Commit abb722b

Browse files
salcodebradyvercher
authored andcommitted
Temporarily suspend PHP Warnings on invalid tags
Temporarily suspend PHP Warnings on invalid tags when processing Gist HTML by setting the libxml_use_internal_errors() value to true. The original value for libxml_use_internal_errors() is restored when the processing is complete. props @Dan0sz See #80 Resolves #81
1 parent d7ae673 commit abb722b

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## [Unreleased]
44

5+
* Temporarily suspend PHP Warnings on invalid tags when processing Gist HTML ([#81](https://github.com/bradyvercher/gistpress/issues/81))
6+
57
## [v3.0.2] - 2020-01-16
68

79
* 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.

includes/class-gistpress.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,10 @@ public function process_gist_html( $html, array $args ) {
463463
$html = '<?xml encoding="utf-8" ?>' . $html;
464464

465465
$dom = new DOMDocument();
466+
467+
// Temporarily suppress warnings for invalid tags.
468+
$previous_libxml_use_internal_errors_value = libxml_use_internal_errors( true );
469+
466470
$dom->loadHTML( $html, LIBXML_HTML_NODEFDTD | LIBXML_HTML_NOIMPLIED );
467471

468472
$lines = $dom->getElementsByTagName( 'tr' );
@@ -537,6 +541,9 @@ public function process_gist_html( $html, array $args ) {
537541
$html = $this->process_gist_line_numbers( $html, $args['lines'], $args['lines_start'] );
538542
}
539543

544+
// Reset to previous value.
545+
libxml_use_internal_errors( $previous_libxml_use_internal_errors_value );
546+
540547
return $html;
541548
}
542549

0 commit comments

Comments
 (0)