File tree Expand file tree Collapse file tree 3 files changed +31
-7
lines changed
Expand file tree Collapse file tree 3 files changed +31
-7
lines changed Original file line number Diff line number Diff line change 44
55use App \Models \Enums \ChatMessageType ;
66use App \Models \Legacy \ChatMessage ;
7+ use App \Rules \FluxEditorRule ;
78use Illuminate \Support \Collection ;
89use Livewire \Component ;
910
@@ -33,9 +34,7 @@ public function render()
3334 public function save ()
3435 {
3536
36- $ this ->validate (['content ' => 'required|min:1 ' ]);
37-
38- $ cleanContent = strip_tags ((string ) $ this ->content , '<p><br><strong><em><ul><ol><li><a><h1><h2><h3> ' );
37+ $ cleanContent = $ this ->validate (['content ' => ['required ' , 'min:1 ' , new FluxEditorRule ()]])['content ' ];
3938
4039 ChatMessage::create ([
4140 'text ' => $ cleanContent ,
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace App \Rules ;
4+
5+ use Closure ;
6+ use Illuminate \Contracts \Validation \ValidationRule ;
7+ use Illuminate \Translation \PotentiallyTranslatedString ;
8+
9+ class FluxEditorRule implements ValidationRule
10+ {
11+ /**
12+ * Run the validation rule.
13+ *
14+ * @param \Closure(string, ?string=): PotentiallyTranslatedString $fail
15+ */
16+ public function validate (string $ attribute , mixed $ value , Closure $ fail ): void
17+ {
18+ $ cleanContent = strip_tags ((string ) $ value , '<p><s><br><strong><em><ul><ol><li><a><h1><h2><h3> ' );
19+ if ($ cleanContent !== $ value ) {
20+ $ fail (__ ('errors.flux-editor-malicious-html ' ));
21+ }
22+ }
23+ }
Original file line number Diff line number Diff line change @@ -47,20 +47,22 @@ class="font-medium text-gray-900">{{ $message->user->name ?? $message->creator_a
4747
4848 <!-- New comment form -->
4949 <div class =" mt-6 flex gap-x-3" >
50-
5150 <div class =" -ml-1 mt-3" >
5251 <x-profile-pic />
5352 </div >
54- <form action = " # " class =" relative flex-auto" >
53+ <div class =" relative flex-auto" >
5554 <div class =" overflow-hidden" >
5655 <flux:editor wire:model =" content" />
57- </div >
5856
57+ </div >
5958 <div class =" py-2 pr-2 pl-3 bottom-0 absolute right-0" >
6059 <flux:button wire:click =" save" variant =" primary" color =" indigo" icon =" paper-airplane" ></flux:button >
6160 </div >
62- </form >
61+ </div >
6362 </div >
63+ @error (' content' )
64+ <div class =" ml-14 mt-2 text-sm text-red-600" >{{ $message } } </div >
65+ @enderror
6466
6567
6668</div >
You can’t perform that action at this time.
0 commit comments