Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions src/Parameter/EncryptParameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -133,15 +133,15 @@ 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

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);
Expand Down Expand Up @@ -172,14 +172,20 @@ 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 (strtolower($key) == 'apikey') {
$invalidCharsFlattened = str_replace('|\=|', '|', $invalidCharsFlattened);
}

if (preg_match_all('#' . $invalidCharsFlattened . '#', $value, $matches)) {
$invalidCharsMatched = '"' . implode('", "', $matches[0]) . '"';
throw new InvalidArgumentException(
'String ' . $value . ' contains invalid chars (i.e.: ' . $invalidCharsMatched . ').'
Expand Down