Repository navigation
fix: don't wrap addition and deletion delimiters twice in embedded languages - #245
Merged
brendt merged 2 commits intoOct 27, 2026
Merged
Conversation
Benchmark ResultsComparison of Open to see the benchmark results
Generated by phpbench against commit fce86f7 |
There was a problem hiding this comment.
🟢 Approval recommended
The narrowly scoped guards match the existing ignore-token format, with focused regression coverage and no identified blocking issues.
No open issues 🎉
What changed in this PR
Fixes duplicate wrapping of addition and deletion delimiters when embedded code is highlighted, preventing malformed spans and lost delimiters.
Changes:
- Adds guards to all four delimiter patterns to skip delimiters already wrapped in ignore tokens.
- Adds pattern-level checks for wrapped delimiters and rendered HTML regression tests for markers ending inside
<script>.
| File | Description |
|---|---|
tests/Languages/Base/Injections/DeletionInjectionTest.php |
Tests deletion markers ending inside embedded JavaScript. |
tests/Languages/Base/Injections/AdditionInjectionTest.php |
Tests addition markers ending inside embedded JavaScript. |
src/Languages/Base/Patterns/DeletionStartTokenPattern.php |
Skips already-wrapped deletion opening delimiters. |
src/Languages/Base/Patterns/DeletionEndTokenPattern.php |
Skips already-wrapped deletion closing delimiters. |
src/Languages/Base/Patterns/AdditionStartTokenPattern.php |
Skips already-wrapped addition opening delimiters. |
src/Languages/Base/Patterns/AdditionEndTokenPattern.php |
Skips already-wrapped addition closing delimiters. |
Review effort: Balanced
Member
|
Thank you :) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related to #125
{-<script>-}in HTML rendered an empty<span class="ignore"></span>in the output, and the-}disappeared. The same happens with{+ +}, and in Blade, Vue and Svelte.Cause
The code inside
<script>is highlighted by a nested highlighter, which wraps-}in an ignore token. The outer HTML patterns then run on content that already contains that rendered code, soDeletionEndTokenPatternfinds the same-}and wraps it a second time.DeletionInjectiononly unwraps one level, and its regex then consumes the-}that's left inside the span.Fix
The four delimiter patterns don't match a delimiter that is already wrapped in an ignore token.
Tests
PatternTestcases for an already wrapped delimiter on the four patterns<script>I also wrapped each line of the bench fixtures in
{- -}and{+ +}(3,946 runs): broken outputs go from 608 to 488 onmain. Most of the remaining ones are lines that already contain braces, the same kind of collision as #240.