From 5f985c36c0621dbf842260e1daa11cc65673b3b4 Mon Sep 17 00:00:00 2001 From: Jeremy Dormitzer Date: Sat, 30 Mar 2019 11:26:39 -0400 Subject: [PATCH] Handle unicode in response properly --- src/Controllers/GetController.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Controllers/GetController.php b/src/Controllers/GetController.php index 1304612..7f31db6 100644 --- a/src/Controllers/GetController.php +++ b/src/Controllers/GetController.php @@ -105,15 +105,21 @@ class GetController }; } $pagedCollection = $this->collectionsService->pageAndFilterCollection( $request, $object, $filterFunc ); - - return new JsonResponse( $pagedCollection ); + return $this->makeJsonResponse( $pagedCollection ); } - $response = new JsonResponse( $object->asArray() ); + $response = $this->makeJsonResponse( $object->asArray() ); if ( $object->hasField( 'type' ) && $object['type'] === 'Tombstone' ) { $response->setStatusCode( 410 ); } return $response; } + + private function makeJsonResponse( $obj ) + { + $response = new Response( json_encode( $obj, JSON_UNESCAPED_UNICODE ) ); + $response->headers->set( 'Content-Type', 'application/json' ); + return $response; + } }