From c6afdf81301932525e818d761f8d64d7b7359b0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Thu, 28 Apr 2022 10:10:04 +0200 Subject: [PATCH 1/3] Fix PDO URI test --- ext/pdo_mysql/tests/pdo_mysql___construct_uri.phpt | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/ext/pdo_mysql/tests/pdo_mysql___construct_uri.phpt b/ext/pdo_mysql/tests/pdo_mysql___construct_uri.phpt index 99cd631a4a2ca..6dac0a716c810 100644 --- a/ext/pdo_mysql/tests/pdo_mysql___construct_uri.phpt +++ b/ext/pdo_mysql/tests/pdo_mysql___construct_uri.phpt @@ -18,7 +18,7 @@ MySQLPDOTest::skip(); $dsn = MySQLPDOTest::getDSN(); $user = PDO_MYSQL_TEST_USER; $pass = PDO_MYSQL_TEST_PASS; - $uri = sprintf('uri:file://%s', (substr(PHP_OS, 0, 3) == 'WIN' ? str_replace('\\', '/', $file) : $file)); + $uri = 'uri:file://' . $file; if ($fp = @fopen($file, 'w')) { // ok, great we can create a file with a DSN in it @@ -38,8 +38,8 @@ MySQLPDOTest::skip(); } if ($fp = @fopen($file, 'w')) { - fwrite($fp, sprintf('mysql:dbname=letshopeinvalid;%s%s', - chr(0), $dsn)); + $dsnUnknownDatabase = preg_replace('~dbname=[^;]+~', 'dbname=letshopeinvalid', $dsn); + fwrite($fp, $dsnUnknownDatabase); fclose($fp); clearstatcache(); assert(file_exists($file)); @@ -49,9 +49,8 @@ MySQLPDOTest::skip(); $expected = array( "SQLSTATE[HY000] [1049] Unknown database 'letshopeinvalid'", "SQLSTATE[42000] [1049] Unknown database 'letshopeinvalid'", - "SQLSTATE[HY000] [2002] No such file or directory" ); - printf("[003] URI=%s, DSN=%s, File=%s (%d bytes, '%s'), chr(0) test, %s\n", + printf("[003] URI=%s, DSN=%s, File=%s (%d bytes, '%s'), %s\n", $uri, $dsn, $file, filesize($file), file_get_contents($file), (in_array($e->getMessage(), $expected) ? 'EXPECTED ERROR' : $e->getMessage())); @@ -73,5 +72,5 @@ MySQLPDOTest::skip(); print "done!"; ?> --EXPECTF-- -[003] URI=uri:file://%spdomuri.tst, DSN=mysql%sdbname=%s, File=%spdomuri.tst (%d bytes, 'mysql%sdbname=letshopeinvalid%s'), chr(0) test, EXPECTED ERROR +[003] URI=uri:file://%spdomuri.tst, DSN=mysql:%sdbname=%s, File=%spdomuri.tst (%d bytes, 'mysql:%sdbname=letshopeinvalid%S'), EXPECTED ERROR done! From d708bf7a34313bc83c60c17787c8660e7a23332f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Thu, 28 Apr 2022 14:52:29 +0200 Subject: [PATCH 2/3] keep testing chr(0) in DSN --- ext/pdo_mysql/tests/pdo_mysql___construct_uri.phpt | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/ext/pdo_mysql/tests/pdo_mysql___construct_uri.phpt b/ext/pdo_mysql/tests/pdo_mysql___construct_uri.phpt index 6dac0a716c810..9860dcda671e7 100644 --- a/ext/pdo_mysql/tests/pdo_mysql___construct_uri.phpt +++ b/ext/pdo_mysql/tests/pdo_mysql___construct_uri.phpt @@ -38,7 +38,8 @@ MySQLPDOTest::skip(); } if ($fp = @fopen($file, 'w')) { - $dsnUnknownDatabase = preg_replace('~dbname=[^;]+~', 'dbname=letshopeinvalid', $dsn); + $dsnUnknownDatabase = preg_replace('~dbname=[^;]+~', 'dbname=letshopeinvalid', $dsn) + . chr(0) . ';host=nonsense;unix_socket=nonsense'; fwrite($fp, $dsnUnknownDatabase); fclose($fp); clearstatcache(); @@ -60,8 +61,6 @@ MySQLPDOTest::skip(); } - /* TODO: safe mode */ - } catch (PDOException $e) { printf("[001] %s, [%s] %s\n", $e->getMessage(), @@ -72,5 +71,5 @@ MySQLPDOTest::skip(); print "done!"; ?> --EXPECTF-- -[003] URI=uri:file://%spdomuri.tst, DSN=mysql:%sdbname=%s, File=%spdomuri.tst (%d bytes, 'mysql:%sdbname=letshopeinvalid%S'), EXPECTED ERROR +[003] URI=uri:file://%spdomuri.tst, DSN=mysql:%sdbname=%s, File=%spdomuri.tst (%d bytes, 'mysql:%sdbname=letshopeinvalid%snonsense'), EXPECTED ERROR done! From feed0dba30601397090786db08664144409c7ccf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Mon, 2 May 2022 11:08:46 +0200 Subject: [PATCH 3/3] reuse 1st test to test chr(0) behaviour as much as possible --- .../tests/pdo_mysql___construct_uri.phpt | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/ext/pdo_mysql/tests/pdo_mysql___construct_uri.phpt b/ext/pdo_mysql/tests/pdo_mysql___construct_uri.phpt index 9860dcda671e7..982845499e2e9 100644 --- a/ext/pdo_mysql/tests/pdo_mysql___construct_uri.phpt +++ b/ext/pdo_mysql/tests/pdo_mysql___construct_uri.phpt @@ -21,7 +21,6 @@ MySQLPDOTest::skip(); $uri = 'uri:file://' . $file; if ($fp = @fopen($file, 'w')) { - // ok, great we can create a file with a DSN in it fwrite($fp, $dsn); fclose($fp); clearstatcache(); @@ -38,23 +37,17 @@ MySQLPDOTest::skip(); } if ($fp = @fopen($file, 'w')) { - $dsnUnknownDatabase = preg_replace('~dbname=[^;]+~', 'dbname=letshopeinvalid', $dsn) - . chr(0) . ';host=nonsense;unix_socket=nonsense'; - fwrite($fp, $dsnUnknownDatabase); + fwrite($fp, $dsn . chr(0) . ';host=nonsense;unix_socket=nonsense'); fclose($fp); clearstatcache(); assert(file_exists($file)); try { $db = new PDO($uri, $user, $pass); } catch (PDOException $e) { - $expected = array( - "SQLSTATE[HY000] [1049] Unknown database 'letshopeinvalid'", - "SQLSTATE[42000] [1049] Unknown database 'letshopeinvalid'", - ); printf("[003] URI=%s, DSN=%s, File=%s (%d bytes, '%s'), %s\n", - $uri, $dsn, - $file, filesize($file), file_get_contents($file), - (in_array($e->getMessage(), $expected) ? 'EXPECTED ERROR' : $e->getMessage())); + $uri, $dsn, + $file, filesize($file), file_get_contents($file), + $e->getMessage()); } unlink($file); } @@ -71,5 +64,4 @@ MySQLPDOTest::skip(); print "done!"; ?> --EXPECTF-- -[003] URI=uri:file://%spdomuri.tst, DSN=mysql:%sdbname=%s, File=%spdomuri.tst (%d bytes, 'mysql:%sdbname=letshopeinvalid%snonsense'), EXPECTED ERROR done!