diff --git a/README.md b/README.md index fb2149147..773536179 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/lib/Cake/Model/Datasource/DboSource.php b/lib/Cake/Model/Datasource/DboSource.php index da3ffb911..d356492df 100644 --- a/lib/Cake/Model/Datasource/DboSource.php +++ b/lib/Cake/Model/Datasource/DboSource.php @@ -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; } } diff --git a/lib/Cake/Model/Datasource/PDOExceptionWithQueryString.php b/lib/Cake/Model/Datasource/PDOExceptionWithQueryString.php new file mode 100644 index 000000000..dd59c9e06 --- /dev/null +++ b/lib/Cake/Model/Datasource/PDOExceptionWithQueryString.php @@ -0,0 +1,17 @@ +getMessage(), 0, $e->getPrevious()); + + $this->code = $e->code; + } +}