@@ -809,6 +809,35 @@ public function it_merges_any_x_data_passed_to_the_tag()
809809 $ this ->assertStringContainsString ($ expected , $ output );
810810 }
811811
812+ #[Test]
813+ public function it_properly_escapes_show_field_js_in_blade ()
814+ {
815+ $ output = $ this ->blade (<<<'EOT'
816+ <s:form:contact js="alpine">
817+ <template x-if="{{ $show_field['message'] }}"></template>
818+ <template x-if="{{ $show_field['my_favourites'] }}"></template>
819+ <template x-if="{{ $show_field['my_favourites.favourite_animals'] }}"></template>
820+ <s:form:fields>
821+ @if ($field['handle'] === 'message')
822+ <template x-if="{{ $field['show_field'] }}"></template>
823+ @endif
824+ </s:form:fields>
825+ </s:form:contact>
826+ EOT
827+ );
828+
829+ preg_match_all ('/<template x-if="(.+)"><\/template>/U ' , $ output , $ js );
830+
831+ $ expected = [
832+ 'Statamic.$conditions.showField( ' .$ this ->jsonEncode (['if ' => ['email ' => 'not empty ' ]]).', $data, \'message \') ' ,
833+ 'Statamic.$conditions.showField( ' .$ this ->jsonEncode (['if ' => ['name ' => 'not empty ' ]]).', $data, \'my_favourites \') ' ,
834+ 'Statamic.$conditions.showField( ' .$ this ->jsonEncode (['if ' => ['$root.likes_animals ' => 'is true ' ]]).', $data, \'my_favourites.favourite_animals \') ' ,
835+ 'Statamic.$conditions.showField( ' .$ this ->jsonEncode (['if ' => ['email ' => 'not empty ' ]]).', $data, \'message \') ' ,
836+ ];
837+
838+ $ this ->assertSame ($ expected , $ js [1 ]);
839+ }
840+
812841 private function jsonEncode ($ data )
813842 {
814843 return Statamic::modify ($ data )->toJson ()->entities ();
0 commit comments