-
Notifications
You must be signed in to change notification settings - Fork 11.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[9.x] Fixes blade tags issue #45424 🔧 #45490
Conversation
a72d396
to
3dfdef1
Compare
If we are going to attempt to solve that issue should we not add a new test ensuring that issue is actually fixed? |
Yeah, I will add more tests, currently, I have changed the previous test which proves the bug to indicate the fix. |
e25a2f5
to
759089b
Compare
@taylorotwell I think I am done with this PR for now. |
2354c99
to
5015a74
Compare
The first commit solves the problem for closing chars (without touching the original regex) The second commit solves the problem for opening chars (but tweaks the original regex) So if you want to stay really safe and avoid touching the regex, you can keep the first and discard the second one.
|
Can you provide some insight about what happens if it never finds a proper closing parenthesis? Also, do you have some before / after benchmarks of running view:cache with this change on a code base with a fairly large amount of templates? |
Since the user has to provide valid PHP syntax as input for the blade tags, it means that the closing parenthesis should be found or there is a syntax error in the first place, but yeah it is good to have a test about the result and the thrown error.
From experience, I know that the tokenizer is extremely fast. My laravel-microscope package runs the entire application code through tokenizer and all processes the tokens and this usually happens in a fraction of a second on a 10-years-old home PC. |
Alright. Can you maybe add some sort of test case or behavior description for what happens if there is never a closing parenthesis found? |
I added the test for the unclosed blade tag. It seems that they are considered a tag with no parenthesis. |
I spent some time trying to break this today, but it seems to be holding up to everything I've thrown at it. I also booted up a decently sized Blade only project from a few years ago that uses all the older style blade bits (i.e. not <x-whatever) and it seemed happy. I ran Before: 11.34 seconds Don't think there is anything performance-wise to worry about. |
I think I may have found an edge case. The code below is broken on <div>
<span @class([
'lt-text-xs lt-inline-block lt-py-1 lt-px-2 lt-rounded',
'lt-text-green-600 lt-bg-green-50' => !@empty($success),
'lt-text-yellow-600 lt-bg-yellow-50' => !@empty(
$warning
),
'lt-text-red-600 lt-bg-red-50' => !@empty($danger),
])>
{{ $value }}
</span>
</div> This gets compiled to:
And throws the error Context: lunarphp/lunar#822 |
@rubenvanerk I think the fix is somewhat easy. |
solves #45424
The solution seems a bit hacky, but the idea, however, is simple:
in this example, regex finds the :
@include ( 'partial1', ['hell)
first and the loop adds these portions until it reaches the closing:)o' => '
)-
)--
'] )
<=== the closing one.Performance:
Let me note that this part of the code is NOT run during each and every request/response life cycle since the compiled versions of blade files get cached.
Some tests are included to prove the fix.
As I know, Taylor likes to find a proper regex for it and does not like such solutions, maybe the regex can be found somewhere in open-source IDE syntax highlighters like VS code, or people from Jetbrain can help since they can highlight the syntax properly.