From 1b37b7b4b6ca6552fb745209323eaf14d385d7a9 Mon Sep 17 00:00:00 2001 From: Richard Henkenjohann Date: Sat, 11 Apr 2020 12:41:33 +0200 Subject: [PATCH] Decode parameters in URL (#12) * Decode parameters in URL * Add test case for DSN with special characters --- src/DSN.php | 8 ++++---- tests/DsnTest.php | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/DSN.php b/src/DSN.php index 1f16667..ea3982d 100644 --- a/src/DSN.php +++ b/src/DSN.php @@ -174,10 +174,10 @@ private function parseDsn($dsn) $auth = []; if (2 === count($temp)) { - $auth['username'] = $temp[0]; - $auth['password'] = $temp[1]; + $auth['username'] = rawurldecode($temp[0]); + $auth['password'] = rawurldecode($temp[1]); } else { - $auth['username'] = $temp[0]; + $auth['username'] = rawurldecode($temp[0]); $auth['password'] = null; } @@ -196,7 +196,7 @@ private function parseDsn($dsn) if (isset($temp[1])) { $params = $temp[1]; $temp = explode('?', $params); - $this->database = empty($temp[0]) ? null : $temp[0]; + $this->database = empty($temp[0]) ? null : rawurldecode($temp[0]); if (isset($temp[1])) { $this->parseParameters($temp[1]); } diff --git a/tests/DsnTest.php b/tests/DsnTest.php index ce5b3ea..6a4932c 100644 --- a/tests/DsnTest.php +++ b/tests/DsnTest.php @@ -58,6 +58,7 @@ public function authenticationProvider() { return [ ['mysql://root:root_pass@127.0.0.1:3306/test_db', 'root', 'root_pass', 'username', 'password'], + ['mysql://root:aA%263yuA%3F123-2ABC@127.0.0.1:3306/test_db', 'root', 'aA&3yuA?123-2ABC', 'username', 'password'], ['mysql://127.0.0.1:3306/test_db', null, null, 'username', 'password'], ]; }