Skip to content

Empty code block causes highlight.php warning #189

@westonruter

Description

@westonruter

When adding a Code block, I'm seeing a warning in the error log:

PHP Warning:  DOMDocument::loadHTML(): Empty string supplied as input in /app/public/content/plugins/syntax-highlighting-code-block/vendor/scrivo/highlight.php/HighlightUtilities/functions.php on line 179

It should avoid calling splitCodeIntoArray() if $content is empty:

--- a/syntax-highlighting-code-block.php
+++ b/syntax-highlighting-code-block.php
@@ -510,7 +510,7 @@ function render_block( $attributes, $content ) {
 			require_highlight_php_functions();
 
 			$highlighted_lines = parse_highlighted_lines( $attributes['highlightedLines'] );
-			$lines             = \HighlightUtilities\splitCodeIntoArray( $content );
+			$lines             = empty( $content ) ? [] : \HighlightUtilities\splitCodeIntoArray( $content );
 			$content           = '';
 
 			// We need to wrap the line of code twice in order to let out `white-space: pre` CSS setting to be respected

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingchangeloggedupstreamAn issue related to a problem on a dependency of this plugin

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions