Skip to content

Commit b78f3ab

Browse files
committed
Prevent escaping JSON
1 parent 0d8701f commit b78f3ab

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/Directive.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public static function compile($expression = ''): string
2424
if ($__inertiaSsrResponse) {
2525
echo $__inertiaSsrResponse->body;
2626
} elseif (config(\'inertia.use_script_element_for_initial_page\')) {
27-
?><script data-page="'.$id.'" type="application/json">{{ json_encode($page) }}</script><div id="'.$id.'"></div><?php
27+
?><script data-page="'.$id.'" type="application/json">{!! json_encode($page) !!}</script><div id="'.$id.'"></div><?php
2828
} else {
2929
?><div id="'.$id.'" data-page="{{ json_encode($page) }}"></div><?php
3030
}

tests/DirectiveTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function test_inertia_directive_renders_the_root_element_and_script_eleme
7070
'inertia.use_script_element_for_initial_page' => true,
7171
]);
7272

73-
$html = '<script data-page="app" type="application/json">{&quot;component&quot;:&quot;Foo\/Bar&quot;,&quot;props&quot;:{&quot;foo&quot;:&quot;bar&quot;},&quot;url&quot;:&quot;\/test&quot;,&quot;version&quot;:&quot;&quot;,&quot;encryptHistory&quot;:false,&quot;clearHistory&quot;:false}</script><div id="app"></div>';
73+
$html = '<script data-page="app" type="application/json">{"component":"Foo\/Bar","props":{"foo":"bar"},"url":"\/test","version":"","encryptHistory":false,"clearHistory":false}</script><div id="app"></div>';
7474

7575
$this->assertSame($html, $this->renderView('@inertia', ['page' => self::EXAMPLE_PAGE_OBJECT]));
7676
$this->assertSame($html, $this->renderView('@inertia()', ['page' => self::EXAMPLE_PAGE_OBJECT]));
@@ -106,7 +106,7 @@ public function test_inertia_directive_can_use_a_different_root_element_id_when_
106106
'inertia.use_script_element_for_initial_page' => true,
107107
]);
108108

109-
$html = '<script data-page="foo" type="application/json">{&quot;component&quot;:&quot;Foo\/Bar&quot;,&quot;props&quot;:{&quot;foo&quot;:&quot;bar&quot;},&quot;url&quot;:&quot;\/test&quot;,&quot;version&quot;:&quot;&quot;,&quot;encryptHistory&quot;:false,&quot;clearHistory&quot;:false}</script><div id="foo"></div>';
109+
$html = '<script data-page="foo" type="application/json">{"component":"Foo\/Bar","props":{"foo":"bar"},"url":"\/test","version":"","encryptHistory":false,"clearHistory":false}</script><div id="foo"></div>';
110110

111111
$this->assertSame($html, $this->renderView('@inertia(foo)', ['page' => self::EXAMPLE_PAGE_OBJECT]));
112112
$this->assertSame($html, $this->renderView("@inertia('foo')", ['page' => self::EXAMPLE_PAGE_OBJECT]));

0 commit comments

Comments
 (0)