From 6fa42e70acf69219a98ee204bb44b96b69215798 Mon Sep 17 00:00:00 2001 From: Matteo Schiona Date: Mon, 24 Feb 2020 17:24:51 +0100 Subject: [PATCH 1/3] Fix apiKey = char --- src/Parameter/EncryptParameter.php | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/Parameter/EncryptParameter.php b/src/Parameter/EncryptParameter.php index e6508c4..3fd360a 100644 --- a/src/Parameter/EncryptParameter.php +++ b/src/Parameter/EncryptParameter.php @@ -121,10 +121,10 @@ public function __construct(array $parameters = []) */ public function set($key, $value) { - if (!in_array($key, $this->parametersName, true)) { + if (! in_array($key, $this->parametersName, true)) { throw new InvalidArgumentException(sprintf('%s is not a valid parameter name.', $key)); } - $this->verifyParameterValidity($value); + $this->verifyParameterValidity($value, $key); parent::set($key, $value); } @@ -133,7 +133,7 @@ public function set($key, $value) */ public function setCustomInfo($customInfo) { - if (!is_array($customInfo)) { + if (! is_array($customInfo)) { $this->data['customInfo'] = $customInfo; } else { //check string validity @@ -141,7 +141,7 @@ public function setCustomInfo($customInfo) foreach ($customInfo as $key => $value) { $value = urlencode($value); $this->verifyParameterValidity($key); - $this->verifyParameterValidity($value); + $this->verifyParameterValidity($value, $key); if (strlen($value) > 300) { $value = substr($value, 0, 300); @@ -172,14 +172,22 @@ public function getCustomInfoToArray() * @param $value * @return bool */ - public function verifyParameterValidity($value) + public function verifyParameterValidity($value, $key = null) { if ('' === $this->invalidCharsFlattened) { $invalidCharsQuoted = array_map('preg_quote', $this->invalidChars); $this->invalidCharsFlattened = implode('|', $invalidCharsQuoted); } - if (preg_match_all('#' . $this->invalidCharsFlattened . '#', $value, $matches)) { + $invalidCharsFlattened = $this->invalidCharsFlattened; + + if ($key == 'apiKey') { + if (($key = array_search('=', $invalidCharsFlattened)) !== false) { + unset($invalidCharsFlattened[$key]); + } + } + + if (preg_match_all('#' . $invalidCharsFlattened . '#', $value, $matches)) { $invalidCharsMatched = '"' . implode('", "', $matches[0]) . '"'; throw new InvalidArgumentException( 'String ' . $value . ' contains invalid chars (i.e.: ' . $invalidCharsMatched . ').' From 6439a54c6eb4a2867dfa9b3251dfd28ab4c6809e Mon Sep 17 00:00:00 2001 From: Matteo Schiona Date: Mon, 24 Feb 2020 17:46:05 +0100 Subject: [PATCH 2/3] Fix apiKey = char --- src/Parameter/EncryptParameter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Parameter/EncryptParameter.php b/src/Parameter/EncryptParameter.php index 3fd360a..6cedf72 100644 --- a/src/Parameter/EncryptParameter.php +++ b/src/Parameter/EncryptParameter.php @@ -181,7 +181,7 @@ public function verifyParameterValidity($value, $key = null) $invalidCharsFlattened = $this->invalidCharsFlattened; - if ($key == 'apiKey') { + if (strtolower($key) == 'apikey') { if (($key = array_search('=', $invalidCharsFlattened)) !== false) { unset($invalidCharsFlattened[$key]); } From af57fc6b6bde89f6c04757263f05cebc4b59a099 Mon Sep 17 00:00:00 2001 From: Matteo Schiona Date: Mon, 24 Feb 2020 17:51:20 +0100 Subject: [PATCH 3/3] Fix --- src/Parameter/EncryptParameter.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Parameter/EncryptParameter.php b/src/Parameter/EncryptParameter.php index 6cedf72..30908b0 100644 --- a/src/Parameter/EncryptParameter.php +++ b/src/Parameter/EncryptParameter.php @@ -182,9 +182,7 @@ public function verifyParameterValidity($value, $key = null) $invalidCharsFlattened = $this->invalidCharsFlattened; if (strtolower($key) == 'apikey') { - if (($key = array_search('=', $invalidCharsFlattened)) !== false) { - unset($invalidCharsFlattened[$key]); - } + $invalidCharsFlattened = str_replace('|\=|', '|', $invalidCharsFlattened); } if (preg_match_all('#' . $invalidCharsFlattened . '#', $value, $matches)) {