-
Notifications
You must be signed in to change notification settings - Fork 10.8k
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
[10.x] Fix issue with @json incorrectly compiling when argument has one or more commas #46910
Conversation
Appreciate you sending in the PR. I just want to stress being careful with this because we've had numerous occasions in the past where we tried to adjust the compiler only to break other use cases for people. |
I totally agree with you there, that's also the reason I marked it as draft. Ideally we should handle all possible argument formats but I feel like that might be more trouble than it's worth. Especially since the workaround of just using |
Your tests do not include the Although your regex looks good and I cant find any obvious issues with some extra structs that i tested, it seems like the best way forward is to just use simple expressions whenever you are using |
I didn't include them since they are already tested in the test above, this test only makes sure the arguments are rendered correctly. But I totally agree with your second point, it needs a lot more cases. Also just realised that heredoc and nowdoc probably don't even work. I guess to get this working for all possible cases we'd have to use |
d8b6d7b
to
54aa659
Compare
It indeed fails on heredoc and nowdoc strings as expected when parsing using regex. To get it working using the php parser was actually a lot easier than expected. The php parser is currently only available when the dev dependencies are installed. This means we would need to add it as a dependency which is probably not something we would like to do for something like this |
Honestly it wouldnt be a bad idea to just bite the bullet and discard/deprecate this blade directive, in favor of something like: {{ json($params) }} // helpers.php
function json($value, $flags, $depth) {
return new \Illuminate\Support\HtmlString(json_encode(...func_get_args()));
} ( It makes no sense to apply all this difficult parsing of arguments. The sole reason we can't do |
You can already do that with the
I'd suggest adding more methods into that if there are use cases it doesn't support. |
Thx I've added a PR that exposes one of the functions in that class for this reason. The |
The only reason I'd use the Also, I didn't realise the |
I ran into the issue as described in #46908 myself recently and fixed it by parsing the arguments using
preg_split
instead of a simpleexplode
.The regex is a slightly modified version of the one from the SO answer below. It now also ensures that commas within parentheses and brackets are ignored.
https://stackoverflow.com/questions/18893390/splitting-on-comma-outside-quotes/18893443#18893443
We should probably add more cases to the
jsonArgumentsProvider
data provider before even considering merging this.