-
Notifications
You must be signed in to change notification settings - Fork 11.5k
Closed
Description
- Laravel Version: 6.20.43
- PHP Version: 7.4.27 and 8.0.14
- Database Driver & Version: pgsql 13
Description:
View helper @json
fails when old()
is used (or any function with comma) and laravel return invalid HTML.
As you can see in source code of json helper it always use comma as delimeter of parameters. But when you use function with parameters, this implode inside parameters and broke parsing.
Steps To Reproduce:
{-- Form::getModel()->name === "O'brien" --}
<my-vue-form
:test1='@json( "O'brien" )'
:test2='@json( Form::getModel()->name )'
:test3='@json( old('name', Form::getModel()->name ?? null) )'
:test4='@json( old('name', Form::getModel()->name ?? null), 15, 255 )'
/>
will compile to:
:test1='<?php echo json_encode( "O'brien" , 15, 512) ?>'
:test2='<?php echo json_encode( Form::getModel()->name , 15, 512) ?>'
:test3='<?php echo json_encode( old('name', Form::getModel()->name ?? null), 512) ?>'
:test4='<?php echo json_encode( old('name', Form::getModel()->name ?? null), 15) ?>'
and echo:
:test1='"O\u0027brien"'
:test2='"O\u0027brien"'
:test3='"O'brien"'
:test4='"O\u0027brien"'
Problems:
- test3 parses
$json = "old('name'";
$options = " Form::getModel()->name ?? null)"
- test3 have bad flags: 512 (default depth) instead of default 15 and break html output because doesn't escape apos - page is broken
- test3 missing depth parameter
- test4 is not very good workaround, because you need to force $options - but it's parsed as $depth
- test4 missing inserted depth parameter
- if you use function with 3 params, you cant input options at all
- if you use function with more then 3 params, they will be ignored at all and cause a 500 Server Error
Expectation:
@json
helper have support to use functions in it.
Workaround
For my usage it is possible to write this without comma (but it's only this specific case when old is used)
:test3='@json( old('name', Form::getModel()->name ?? null) )'
:test3='@json( old('name') ?? Form::getModel()->name ?? null )'
Metadata
Metadata
Assignees
Labels
No labels