"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/Form/FormProtector.php" between
cakephp-4.0.1.tar.gz and cakephp-4.0.2.tar.gz

About: CakePHP is a rapid development framework for PHP applications. Source code.

FormProtector.php  (cakephp-4.0.1):FormProtector.php  (cakephp-4.0.2)
skipping to change at line 50 skipping to change at line 50
protected $fields = []; protected $fields = [];
/** /**
* Unlocked fields. * Unlocked fields.
* *
* @var array * @var array
*/ */
protected $unlockedFields = []; protected $unlockedFields = [];
/** /**
* Form URL
*
* @var string
*/
protected $url = '';
/**
* Session Id
*
* @var string
*/
protected $sessionId = '';
/**
* Error message providing detail for failed validation. * Error message providing detail for failed validation.
* *
* @var string|null * @var string|null
*/ */
protected $debugMessage; protected $debugMessage;
/** /**
* Construct. * Construct.
* *
* @param string $url Form URL.
* @param string $sessionId Session Id.
* @param array $data Data array, can contain key `unlockedFields` with list of unlocked fields. * @param array $data Data array, can contain key `unlockedFields` with list of unlocked fields.
*/ */
public function __construct(string $url = '', string $sessionId = '', array $data = []) public function __construct(array $data = [])
{ {
$this->url = $url;
$this->sessionId = $sessionId;
if (!empty($data['unlockedFields'])) { if (!empty($data['unlockedFields'])) {
$this->unlockedFields = $data['unlockedFields']; $this->unlockedFields = $data['unlockedFields'];
} }
} }
/** /**
* Validate submitted form data. * Validate submitted form data.
* *
* @param mixed $formData Form data. * @param mixed $formData Form data.
* @param string $url URL form was POSTed to. * @param string $url URL form was POSTed to.
skipping to change at line 395 skipping to change at line 376
$unlocked = explode('|', $unlocked); $unlocked = explode('|', $unlocked);
sort($unlocked, SORT_STRING); sort($unlocked, SORT_STRING);
return $unlocked; return $unlocked;
} }
/** /**
* Generate the token data. * Generate the token data.
* *
* @param string $url Form URL.
* @param string $sessionId Session Id.
* @return array The token data. * @return array The token data.
* @psalm-return array{fields: string, unlocked: string} * @psalm-return array{fields: string, unlocked: string}
*/ */
public function buildTokenData(): array public function buildTokenData(string $url = '', string $sessionId = ''): ar ray
{ {
$fields = $this->fields; $fields = $this->fields;
$unlockedFields = $this->unlockedFields; $unlockedFields = $this->unlockedFields;
$locked = []; $locked = [];
foreach ($fields as $key => $value) { foreach ($fields as $key => $value) {
if (is_numeric($value)) { if (is_numeric($value)) {
$value = (string)$value; $value = (string)$value;
} }
if (!is_int($key)) { if (!is_int($key)) {
$locked[$key] = $value; $locked[$key] = $value;
unset($fields[$key]); unset($fields[$key]);
} }
} }
sort($unlockedFields, SORT_STRING); sort($unlockedFields, SORT_STRING);
sort($fields, SORT_STRING); sort($fields, SORT_STRING);
ksort($locked, SORT_STRING); ksort($locked, SORT_STRING);
$fields += $locked; $fields += $locked;
$fields = $this->generateHash($fields, $unlockedFields, $this->url, $thi s->sessionId); $fields = $this->generateHash($fields, $unlockedFields, $url, $sessionId );
$locked = implode('|', array_keys($locked)); $locked = implode('|', array_keys($locked));
return [ return [
'fields' => urlencode($fields . ':' . $locked), 'fields' => urlencode($fields . ':' . $locked),
'unlocked' => urlencode(implode('|', $unlockedFields)), 'unlocked' => urlencode(implode('|', $unlockedFields)),
'debug' => urlencode(json_encode([ 'debug' => urlencode(json_encode([
$this->url, $url,
$this->fields, $this->fields,
$this->unlockedFields, $this->unlockedFields,
])), ])),
]; ];
} }
/** /**
* Generate validation hash. * Generate validation hash.
* *
* @param array $fields Fields list. * @param array $fields Fields list.
skipping to change at line 598 skipping to change at line 581
} }
/** /**
* Return debug info * Return debug info
* *
* @return array * @return array
*/ */
public function __debugInfo(): array public function __debugInfo(): array
{ {
return [ return [
'url' => $this->url,
'sessionId' => $this->sessionId,
'fields' => $this->fields, 'fields' => $this->fields,
'unlockedFields' => $this->unlockedFields, 'unlockedFields' => $this->unlockedFields,
'debugMessage' => $this->debugMessage, 'debugMessage' => $this->debugMessage,
]; ];
} }
} }
 End of changes. 9 change blocks. 
25 lines changed or deleted 6 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)