Beautiful Open-Source Form Builder
fix: preserve strikethrough in form help text (#1272)
Julien Nahum4f6f371ce0cf
diff --git a/api/config/purify.php b/api/config/purify.phpindex 768f97d4a..f6d1b0ee8 100644--- a/api/config/purify.php+++ b/api/config/purify.php@@ -40,7 +40,7 @@ return ['configs' => ['default' => [- 'HTML.Allowed' => 'h1,h2,b,u,strong,i,em,a[href|title],ul,ol,li,p,br,span[mention|mention-field-id|mention-field-name|mention-fallback],*[style]',+ 'HTML.Allowed' => 'h1,h2,b,u,s,strong,i,em,a[href|title],ul,ol,li,p,br,span[mention|mention-field-id|mention-field-name|mention-fallback],*[style]','HTML.ForbiddenElements' => '','CSS.AllowedProperties' => 'font,font-size,font-weight,font-style,text-decoration,color,text-align',diff --git a/api/tests/Feature/Forms/FormTest.php b/api/tests/Feature/Forms/FormTest.phpindex 4f97c74a2..8c937d663 100644--- a/api/tests/Feature/Forms/FormTest.php+++ b/api/tests/Feature/Forms/FormTest.php@@ -182,6 +182,22 @@ it('can update a form', function () {]);});+it('preserves strikethrough formatting when updating field help text', function () {+ $user = $this->actingAsUser();+ $workspace = $this->createUserWorkspace($user);+ $form = $this->createForm($user, $workspace);++ $formData = (new \App\Http\Resources\FormResource($form))->toArray(request());+ $formData['properties'][0]['help'] = '<p><s onclick="alert(1)">Unavailable option</s></p>';++ $this->putJson(route('open.forms.update', $form->id), $formData)+ ->assertSuccessful()+ ->assertJsonPath('form.properties.0.help', '<p><s>Unavailable option</s></p>');++ expect($form->fresh()->properties[0]['help'])+ ->toBe('<p><s>Unavailable option</s></p>');+});+it('truncates form titles longer than the database limit when updating a form', function () {$user = $this->actingAsUser();$workspace = $this->createUserWorkspace($user);diff --git a/api/tests/Unit/Service/Forms/FormDataNormalizerTest.php b/api/tests/Unit/Service/Forms/FormDataNormalizerTest.phpindex b0d050925..8c91d858c 100644--- a/api/tests/Unit/Service/Forms/FormDataNormalizerTest.php+++ b/api/tests/Unit/Service/Forms/FormDataNormalizerTest.php@@ -27,3 +27,17 @@ it('uses one normalization path for form titles, properties, and select options'->and($normalized['properties'][0]['select']['options'][0]['id'])->toBe('First')->and($normalized['properties'][0]['id'])->toBeString()->not->toBeEmpty();});++it('preserves strikethrough help text while removing unsafe markup', function () {+ $normalized = app(FormDataNormalizer::class)->normalizeProperties([+ [+ 'type' => 'select',+ 'help' => '<p><s onclick="alert(1)">Unavailable option</s></p><script>alert(1)</script>',+ ],+ ]);++ expect($normalized[0]['help'])+ ->toContain('<s>Unavailable option</s>')+ ->not->toContain('onclick')+ ->not->toContain('<script>');+});