Skip to content

Only strip the delimiters of matched custom class blocks - #217

Open
Amoifr wants to merge 1 commit into
tempestphp:mainfrom
Amoifr:fix-206-custom-class-literal-end-token
Open

Amoifr wants to merge 1 commit into
tempestphp:mainfrom
Amoifr:fix-206-custom-class-literal-end-token

Conversation

@Amoifr

@Amoifr Amoifr commented Oct 5, 2026

Copy link
Copy Markdown

Fixes #206.

CustomClassInjection::parse() removed the block delimiters with a global str_replace(), so as soon as a snippet contains one {:class:...:} block, every other :} in it is removed as well, and the tokens after it are rendered at the wrong position. For example:

{:hl-em:x:} = "{:}".format(y)
print({:hl-em:x:})

was rendered as x = "{".format(y) and print(x)x.

The content is now built with preg_replace_callback() on the same pattern, so only the delimiters of the matched blocks are removed. The offsets were already computed against the original string and do not change.

Note: the example from the issue renders fine on main (foo sits at offset 34 of the input, not 33). The bug only shows up when the code itself contains a :} outside of a block, which is what the new test covers.

@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown

Benchmark Results

Comparison of fix-206-custom-class-literal-end-token against main (e04f3d4dd65a7ce3456537584e38cec2eedddd3b).

Open to see the benchmark results
benchmark subject set revs its mem_peak mode rstdev
HighlighterBench benchParse apache 100 5 2.071mb +0.02% 73.865186μs +1.24% ±1.16% -11.75%
HighlighterBench benchParse bash 100 5 2.102mb +0.02% 204.620509μs -0.44% ±0.85% -9.52%
HighlighterBench benchParse bbcode 100 5 2.059mb +0.02% 74.767906μs +0.23% ±0.76% -46.93%
HighlighterBench benchParse blade 100 5 2.675mb +0.02% 1,098.776438μs +0.04% ±0.67% -44.33%
HighlighterBench benchParse css 100 5 2.089mb +0.02% 140.595597μs +0.31% ±0.74% -24.23%
HighlighterBench benchParse diff 100 5 2.093mb +0.02% 99.494971μs +1.56% ±0.75% -32.37%
HighlighterBench benchParse dockerfile 100 5 2.063mb +0.02% 90.474540μs +0.88% ±1.29% +9.06%
HighlighterBench benchParse dotenv 100 5 2.074mb +0.02% 78.078748μs +1.34% ±0.39% -64.56%
HighlighterBench benchParse gdscript 100 5 2.169mb +0.02% 334.997867μs +0.35% ±0.59% -10.47%
HighlighterBench benchParse graphql 100 5 2.090mb +0.02% 153.210078μs -0.16% ±0.39% -43.61%
HighlighterBench benchParse html 100 5 2.093mb +0.02% 117.074892μs +0.29% ±1.67% +225.84%
HighlighterBench benchParse http 100 5 2.063mb +0.02% 25.252838μs +3.46% ±1.42% -33.67%
HighlighterBench benchParse ini 100 5 2.078mb +0.02% 87.198063μs -0.42% ±0.39% -22.09%
HighlighterBench benchParse javascript 100 5 2.157mb +0.02% 273.595714μs -0.76% ±1.21% +2.64%
HighlighterBench benchParse json 100 5 2.132mb +0.02% 239.966712μs -0.32% ±0.63% -22.00%
HighlighterBench benchParse markdown 100 5 2.080mb +0.02% 76.279628μs +0.58% ±0.53% +11.53%
HighlighterBench benchParse nginx 100 5 2.144mb +0.02% 267.734697μs +0.21% ±0.25% -79.84%
HighlighterBench benchParse php 100 5 2.436mb +0.02% 761.280000μs +0.58% ±0.48% -2.92%
HighlighterBench benchParse python 100 5 2.333mb +0.02% 420.367358μs -0.48% ±0.38% -51.32%
HighlighterBench benchParse scss 100 5 2.105mb +0.02% 184.204070μs +0.56% ±0.86% +119.32%
HighlighterBench benchParse sql 100 5 2.104mb +0.02% 159.419550μs +0.05% ±0.41% -28.81%
HighlighterBench benchParse svelte 100 5 2.309mb +0.02% 1,085.331389μs -0.05% ±0.37% -68.18%
HighlighterBench benchParse terminal 100 5 2.099mb +0.02% 189.654403μs +0.77% ±0.46% -17.00%
HighlighterBench benchParse terraform 100 5 2.104mb +0.02% 176.763679μs +1.11% ±0.35% -60.37%
HighlighterBench benchParse typescript 100 5 2.530mb +0.02% 250.980705μs -0.09% ±0.39% -38.49%
HighlighterBench benchParse txt 100 5 2.046mb 0.00% 8.718082μs +3.33% ±1.39% +9.64%
HighlighterBench benchParse twig 100 5 19.211mb +0.00% 1,501.013581μs +2.44% ±0.51% +6.80%
HighlighterBench benchParse vue 100 5 2.387mb +0.02% 420.729530μs +1.19% ±0.40% +79.87%
HighlighterBench benchParse xml 100 5 2.107mb +0.02% 180.108904μs +0.82% ±0.48% -73.34%
HighlighterBench benchParse yaml 100 5 2.165mb +0.02% 319.897299μs -0.08% ±0.37% -81.47%

Generated by phpbench against commit e8dcf5d

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CustomClassInjection: token offsets corrupted when multiple blocks present

1 participant