From 0f5e812e03d7eac1ad8bb9067c4436c57df2e760 Mon Sep 17 00:00:00 2001 From: Miguel N Date: Fri, 29 Jan 2021 16:56:29 +0000 Subject: [PATCH] Usability: Turn CRLF/CR/LF into BR --- app/Http/Controllers/ApplicationController.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/ApplicationController.php b/app/Http/Controllers/ApplicationController.php index 7b74341..0641dd4 100755 --- a/app/Http/Controllers/ApplicationController.php +++ b/app/Http/Controllers/ApplicationController.php @@ -35,6 +35,21 @@ use Illuminate\Support\Facades\Log; class ApplicationController extends Controller { + + private function processOSLinebreaks(array $structuredResponses) + { + $processedResponses = $structuredResponses; + + foreach ($structuredResponses as $responseKey => $response) + { + // We can't use nl2br because it preserves the line breaks and doesn't include all line breaks used by other operating systems + $originalResponse = $response['response']; + $processedResponses[$responseKey]['response'] = str_replace(["\r\n", "\r", "\n"], "
", $originalResponse); + } + + return $processedResponses; + } + private function canVote($votes): bool { $allvotes = collect([]); @@ -64,7 +79,7 @@ class ApplicationController extends Controller [ 'application' => $application, 'comments' => $application->comments, - 'structuredResponses' => json_decode($application->response->responseData, true), + 'structuredResponses' => %this->processOSLinebreaks(json_decode($application->response->responseData, true)), 'formStructure' => $application->response->form, 'vacancy' => $application->response->vacancy, 'canVote' => $this->canVote($application->votes),