Added PDOException wrapper to avoid creating dynamic property. (#77)

This commit is contained in:
Kamil Wylegala 2024-09-21 12:53:44 +02:00 committed by GitHub
parent 7e1da9a5ca
commit 61c8f9ad25
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 26 additions and 3 deletions

View file

@ -59,6 +59,10 @@ It means that composer will look at `master` branch of repository configured und
## Changelog
### 2024-09-21
- Added wrapper for PDOException to avoid creating dynamic property `queryString`.
### 2024-07-24
- Csrf vulnerabity fix back ported from Cake PHP 3

View file

@ -17,6 +17,7 @@
*/
App::uses('DataSource', 'Model/Datasource');
App::uses('PDOExceptionWithQueryString', 'Model/Datasource');
App::uses('CakeText', 'Utility');
App::uses('View', 'View');
@ -512,12 +513,13 @@ class DboSource extends DataSource {
}
return $query;
} catch (PDOException $e) {
$wrapperException = new PDOExceptionWithQueryString($e);
if (isset($query->queryString)) {
$e->queryString = $query->queryString;
$wrapperException->queryString = $query->queryString;
} else {
$e->queryString = $sql;
$wrapperException->queryString = $sql;
}
throw $e;
throw $wrapperException;
}
}

View file

@ -0,0 +1,17 @@
<?php
class PDOExceptionWithQueryString extends PDOException {
public string $queryString = "";
/**
* Wrapper for PDOException to avoid creating dynamic property.
*
* @param PDOException $e Source exception.
*/
public function __construct(PDOException $e) {
parent::__construct($e->getMessage(), 0, $e->getPrevious());
$this->code = $e->code;
}
}