From 1ae9e5952ddc27f515e346dc2590c15bbb98da5d Mon Sep 17 00:00:00 2001 From: Vildan Bina Date: Thu, 21 Nov 2024 12:50:23 +0100 Subject: [PATCH 1/2] fix UTF-8 encoding issue in base64Data function --- src/Handlers/HMAC/Hmac.php | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/Handlers/HMAC/Hmac.php b/src/Handlers/HMAC/Hmac.php index 0ef34533..0bcd5dbf 100644 --- a/src/Handlers/HMAC/Hmac.php +++ b/src/Handlers/HMAC/Hmac.php @@ -28,8 +28,7 @@ abstract class Hmac */ public function uri($uri = null) { - if ($uri) - { + if ($uri) { $uri = preg_replace("#^[^:/.]*[:/]+#i", "", $uri); $this->uri = strtolower(urlencode($uri)); @@ -46,11 +45,13 @@ public function base64Data($data = null) { $this->base64Data = ''; - if ($data) - { - if (is_array($data)) - { - $data = json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRESERVE_ZERO_FRACTION); + if ($data) { + if (is_array($data)) { + $data = mb_convert_encoding( + json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE), + 'UTF-8', + 'auto' + ); } $md5 = md5($data, true); @@ -67,8 +68,7 @@ public function base64Data($data = null) */ public function nonce($nonce = null) { - if ($nonce) - { + if ($nonce) { $this->nonce = $nonce; } @@ -81,8 +81,7 @@ public function nonce($nonce = null) */ public function time($time = null) { - if ($time) - { + if ($time) { $this->time = $time; } From eb56e98e1697808ef0ef65d2b6682caffcbf5102 Mon Sep 17 00:00:00 2001 From: Vildan Bina Date: Thu, 21 Nov 2024 12:51:15 +0100 Subject: [PATCH 2/2] rollback formatting --- src/Handlers/HMAC/Hmac.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/Handlers/HMAC/Hmac.php b/src/Handlers/HMAC/Hmac.php index 0bcd5dbf..5b3befb6 100644 --- a/src/Handlers/HMAC/Hmac.php +++ b/src/Handlers/HMAC/Hmac.php @@ -28,7 +28,8 @@ abstract class Hmac */ public function uri($uri = null) { - if ($uri) { + if ($uri) + { $uri = preg_replace("#^[^:/.]*[:/]+#i", "", $uri); $this->uri = strtolower(urlencode($uri)); @@ -45,8 +46,10 @@ public function base64Data($data = null) { $this->base64Data = ''; - if ($data) { - if (is_array($data)) { + if ($data) + { + if (is_array($data)) + { $data = mb_convert_encoding( json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE), 'UTF-8', @@ -68,7 +71,8 @@ public function base64Data($data = null) */ public function nonce($nonce = null) { - if ($nonce) { + if ($nonce) + { $this->nonce = $nonce; } @@ -81,7 +85,8 @@ public function nonce($nonce = null) */ public function time($time = null) { - if ($time) { + if ($time) + { $this->time = $time; }