diff --git a/src/Core/CoreHelper.php b/src/Core/CoreHelper.php index 2aa31914..856eee6a 100644 --- a/src/Core/CoreHelper.php +++ b/src/Core/CoreHelper.php @@ -159,4 +159,18 @@ public static function GetRequestLogging($serviceContext) return $requestLogger; } + + /** + * Clean up xml response + * @param $string + * @return array|string|null + */ + public static function encodeUTF8($string) + { + $string = preg_replace('/[\x00-\x1F\x7F]/u', '', $string); + if (mb_detect_encoding($string, 'UTF-8', true) === false) { + $string = utf8_encode($string); + } + return $string; + } } diff --git a/src/Core/HttpClients/FaultHandler.php b/src/Core/HttpClients/FaultHandler.php index 50b925bc..ee9df029 100644 --- a/src/Core/HttpClients/FaultHandler.php +++ b/src/Core/HttpClients/FaultHandler.php @@ -197,7 +197,7 @@ public function setResponseBody($body) /** * Return the status code of the Response * - * @return Integer The response status code + * @return int The response status code */ public function getHttpStatusCode() { diff --git a/src/Core/HttpClients/SyncRestHandler.php b/src/Core/HttpClients/SyncRestHandler.php index 9db38d7d..86c04f98 100644 --- a/src/Core/HttpClients/SyncRestHandler.php +++ b/src/Core/HttpClients/SyncRestHandler.php @@ -310,6 +310,7 @@ public function LogAPIRequestToLog($requestBody, $requestUri, $httpHeaders){ * @return string|bool The DOM structured XML */ private function parseStringToDom($string){ + $string = CoreHelper::encodeUTF8($string); $dom = new \DOMDocument(); $dom->preserveWhiteSpace = FALSE; $dom->loadXML($string); diff --git a/src/DataService/DataService.php b/src/DataService/DataService.php index 688ab41b..7ff2bfd6 100644 --- a/src/DataService/DataService.php +++ b/src/DataService/DataService.php @@ -47,7 +47,7 @@ use QuickBooksOnline\API\Data\IPPPreferences; /** - * Class DataServicd + * Class DataService * * This file contains DataService performs CRUD operations on IPP REST APIs. */ @@ -802,13 +802,13 @@ public function Add($entity) $this->verifyOperationAccess($entity, __FUNCTION__); if ($this->isJsonOnly($entity)) { $this->forceJsonSerializers(); - } + } $httpsPostBody = $this->executeObjectSerializer($entity, $urlResource); // Builds resource Uri $resourceURI = implode(CoreConstants::SLASH_CHAR, array('company', $this->serviceContext->realmId, $urlResource)); - $uri = $this->handleTaxService($entity, $resourceURI); + $uri = $this->handleTaxService($entity, $resourceURI); // Send request return $this->sendRequestParseResponseBodyAndHandleHttpError($entity, $uri, $httpsPostBody, DataService::ADD); } @@ -948,7 +948,7 @@ public function DownloadPDF($entity, $dir=null, $returnPdfString = false) return $responseBody; } else { $this->lastError = false; - + return $this->processDownloadedContent(new ContentWriter($responseBody), $responseCode, $dir, $this->getExportFileNameForPDF($entity, "pdf")); } } @@ -1008,7 +1008,7 @@ public function Query($query, $startPosition = null, $maxResults = null, $includ $httpsUri = implode(CoreConstants::SLASH_CHAR, array('company', $this->serviceContext->realmId, 'query')); $httpsPostBody = $this->appendPaginationInfo($query, $startPosition, $maxResults); - + if(!is_null($includes)) { $httpsUri .= "?include=$includes"; } @@ -1024,6 +1024,7 @@ public function Query($query, $startPosition = null, $maxResults = null, $includ $this->lastError = false; $parsedResponseBody = null; try { + $responseBody = CoreHelper::encodeUTF8($responseBody); $responseXmlObj = simplexml_load_string($responseBody); if ($responseXmlObj && $responseXmlObj->QueryResponse) { $tmpXML = $responseXmlObj->QueryResponse->asXML();