diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php index 979e145804..9bb7ace41a 100644 --- a/system/helpers/text_helper.php +++ b/system/helpers/text_helper.php @@ -343,12 +343,12 @@ function highlight_code($str) $str = preg_replace( array( '/<\?php( | )/i', - '/(.*?)\?><\/span>\n<\/span>\n<\/code>/is', + '/(.*?)\?><\/span>(\n<\/span>\n<\/code>|<\/code><\/pre>)/is', '/<\/span>/i' ), array( '', - "$1\n\n", + '$1$2', '' ), $str diff --git a/tests/codeigniter/helpers/text_helper_test.php b/tests/codeigniter/helpers/text_helper_test.php index 43024abdf3..46baab62f2 100644 --- a/tests/codeigniter/helpers/text_helper_test.php +++ b/tests/codeigniter/helpers/text_helper_test.php @@ -104,7 +104,7 @@ public function test_highlight_code() // PHP 8.3 changed highlight_string() output format if (PHP_VERSION_ID >= 80300) { - $expect = "
<?php var_dump(\$this); ?> ?>
"; + $expect = "
<?php var_dump(\$this); ?> 
"; } else { @@ -112,6 +112,18 @@ public function test_highlight_code() } $this->assertEquals($expect, highlight_code('')); + + // Test code without PHP tags (e.g. database queries in profiler) + if (PHP_VERSION_ID >= 80300) + { + $expect_query = "
SELECT * FROM users; 
"; + } + else + { + $expect_query = "\nSELECT FROM users\n\n"; + } + + $this->assertEquals($expect_query, highlight_code('SELECT * FROM users;')); } // ------------------------------------------------------------------------