You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Fatal error when using emphasize tags around a string #148
PHP Fatal error: Uncaught TypeError: str_replace(): Argument #3 ($subject) must be of type array|string, null given in /vendor/tempest/highlight/src/Languages/Base/Injections/AdditionInjection.php:21
Stack trace:
#0 /vendor/tempest/highlight/src/Languages/Base/Injections/AdditionInjection.php(21): str_replace()
#1 /vendor/tempest/highlight/src/Highlighter.php(146): Tempest\Highlight\Languages\Base\Injections\AdditionInjection->parse()
#2 /vendor/tempest/highlight/src/Highlighter.php(96): Tempest\Highlight\Highlighter->parseContent()
#3 reproduce.php(11): Tempest\Highlight\Highlighter->parse()
#4 {main}
thrown in /vendor/tempest/highlight/src/Languages/Base/Injections/AdditionInjection.php on line 21
The fatal error from the original report no longer happens on main, but the output was still broken: $foo = {_"SELECT * FROM users"_}; rendered the string twice ("SELECT * FROM users"SELECT * FROM users").
The cause was in token grouping. The emphasis token became the direct parent of every token it covered, including the SQL keywords inside the string, so its children overlapped and were rendered twice. That could also split the multibyte escape characters in half, which explains the Malformed UTF-8 error you saw with Xdebug.
The PR also fixes related cases:
{* *}, {~ ~} and {:class: :} had the same problem.
Markers around code that contains injections (PHP function parameters, CSS in style, Blade) produced broken markup, and even a fatal error with withGutter().
A word right after a marker wasn't highlighted ({_function), and emphasis inside a string was ignored.
Wrapping code in {_ … _} now renders exactly like the same code without markers, just wrapped in <span class="hl-em">.
Activity
nicwortel commentedon Sep 1, 2024
Strangely enough I'm unable to reproduce the issue with
preg_replacein isolation.When I copy the value of
$contentand try to reproduce this on 3v4l.org it doesn't returnnull:https://3v4l.org/FWi3n
base-zero commentedon Apr 10, 2025
I'm seeing the same issue and error message after upgrading on a page with commonmark content that was working last year and hasn't been changed.
brendt commentedon Apr 10, 2025
I'll look into this! Although I'm a week on holiday currently
Akiyo974 commentedon Oct 20, 2026
I opened #238 to fix this.
The fatal error from the original report no longer happens on
main, but the output was still broken:$foo = {_"SELECT * FROM users"_};rendered the string twice ("SELECT * FROM users"SELECT * FROM users").The cause was in token grouping. The emphasis token became the direct parent of every token it covered, including the SQL keywords inside the string, so its children overlapped and were rendered twice. That could also split the multibyte escape characters in half, which explains the
Malformed UTF-8error you saw with Xdebug.The PR also fixes related cases:
{* *},{~ ~}and{:class: :}had the same problem.style, Blade) produced broken markup, and even a fatal error withwithGutter().{_function), and emphasis inside a string was ignored.Wrapping code in
{_ … _}now renders exactly like the same code without markers, just wrapped in<span class="hl-em">.