Skip to content

Commit

Permalink
Decode parameters in URL (#12)
Browse files Browse the repository at this point in the history
* Decode parameters in URL

* Add test case for DSN with special characters
  • Loading branch information
Richard Henkenjohann authored Apr 11, 2020
1 parent ac1c2f5 commit 1b37b7b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/DSN.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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]);
}
Expand Down
1 change: 1 addition & 0 deletions tests/DsnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public function authenticationProvider()
{
return [
['mysql://root:[email protected]:3306/test_db', 'root', 'root_pass', 'username', 'password'],
['mysql://root:aA%263yuA%[email protected]:3306/test_db', 'root', 'aA&3yuA?123-2ABC', 'username', 'password'],
['mysql://127.0.0.1:3306/test_db', null, null, 'username', 'password'],
];
}
Expand Down

0 comments on commit 1b37b7b

Please sign in to comment.