Skip to content

Commit 551c3f3

Browse files
committed
Update SettingsController
1 parent fc84982 commit 551c3f3

3 files changed

Lines changed: 21 additions & 3 deletions

File tree

app/Http/Controllers/Api/SettingsController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ public function storeBio(UpdateProfileRequest $request)
4747

4848
if ($request->filled('name')) {
4949
$name = $request->input('name') ?: AccountService::getDefaultDisplayName($user->profile_id);
50-
$profile->name = $this->purifyText($name);
51-
$user->name = $this->purifyText($name);
50+
$profile->name = $this->purifyTextWithoutLineBreaks($name);
51+
$user->name = $this->purifyTextWithoutLineBreaks($name);
5252
$user->save();
5353
}
5454

5555
if ($request->filled('bio')) {
56-
$profile->bio = $this->purifyText($request->input('bio'));
56+
$profile->bio = $this->purifyTextWithoutLineBreaks($request->input('bio'));
5757
}
5858

5959
$profile->save();

app/Http/Controllers/Api/Traits/ApiHelpers.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ public static function purifyText($text)
3838
return app(SanitizeService::class)->cleanPlainText($text);
3939
}
4040

41+
public static function purifyTextWithoutLineBreaks($text)
42+
{
43+
return app(SanitizeService::class)->cleanPlainTextWithoutLineBreaks($text);
44+
}
45+
4146
public function success()
4247
{
4348
return response()->json([

app/Services/SanitizeService.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,19 @@ public function cleanPlainText($text)
573573
return trim($cleaned);
574574
}
575575

576+
public function cleanPlainTextWithoutLineBreaks($text)
577+
{
578+
if (empty($text)) {
579+
return '';
580+
}
581+
582+
$cleaned = strip_tags($text);
583+
$cleaned = str_replace(["\r\n", "\r", "\n"], ' ', $cleaned);
584+
$cleaned = preg_replace('/\s+/', ' ', $cleaned);
585+
586+
return trim($cleaned);
587+
}
588+
576589
public function cleanHtmlWithSpacing($html)
577590
{
578591
$blockTags = ['a', 'b', 'blockquote', 'br', 'code', 'del', 'div', 'em', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'i', 'img', 'li', 'ol', 'p', 'pre', 's', 'strike', 'strong', 'u', 'ul'];

0 commit comments

Comments
 (0)