-
Notifications
You must be signed in to change notification settings - Fork 10.9k
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
[12.x] Switch Js::encode() to return HtmlString #50551
base: master
Are you sure you want to change the base?
Conversation
Think so yeah |
@taylorotwell gonna mark this ready for you again if that's okay. |
What would the upgrade guide need to contain? |
The upgrade guide will need to advise that I can see three scenarios that will be affected:
|
@valorin if you need a new review, don't forget to mark the PR as ready. |
Marking this as draft for a bit. |
I wonder this change seems to be a big backward incompatibility. Given: $foo = ['bar' => 'baz']; <div data-foo="{{ Js::encode($foo) }}"> Before: <div data-foo="{"bar":"baz"}">
<!-- div.dataset.foo returns a valid JSON string '{"bar":"baz"}' --> After: <div data-foo="{"bar":"baz"}">
<!-- div.dataset.foo returns '{' and bar":"baz"} will be a garbage --> We should add a cast to escape correctly... <div data-foo="{{ Js::encode($foo)->toString() }}"> Force to use <script type="application/ld+json">{!! Js::encode($ld) !!}</script> |
Since it missed 11 in #49641, let's try again and get it into 12. 🤞
Updating the
Js::encode()
helper to return an instance ofHtmlString
rather than a raw string.The primary reason is to support using the normal escaping Blade tags:
{{ Js::encode() }}
, rather than{!! Js::encode() !}}
, when using this in Blade. This will then match the behaviour already possible withJs::from()
which returns an instance ofHtmlable
and supports{{ Js::from() }}
.Since this is a breaking change, it will need to go into
v11v12 - hence themaster
branch.There are no downsides to this change, it may just require minor code updates - which should be trivial to identify and perform with a search for
Js::encode(
.P.s. Is this the first PR into 12?