Update DSN to support special chars for user and password
Previously, DSN would not be able to parse special characters like "@" or "/". This adds support by requiring the input to be url encoded and then DSN would decode it after parsing.
This commit is contained in:
parent
a22685fd07
commit
b960634088
2 changed files with 36 additions and 3 deletions
|
@ -55,8 +55,8 @@ class DSN
|
|||
}
|
||||
|
||||
$this->scheme = $parts['scheme'] ?? null;
|
||||
$this->user = $parts['user'] ?? null;
|
||||
$this->password = $parts['pass'] ?? null;
|
||||
$this->user = isset($parts['user']) ? \urldecode($parts['user']) : null;
|
||||
$this->password = isset($parts['pass']) ? \urldecode($parts['pass']) : null;
|
||||
$this->host = $parts['host'] ?? null;
|
||||
$this->port = $parts['port'] ?? null;
|
||||
$this->database = $parts['path'] ?? null;
|
||||
|
@ -124,7 +124,7 @@ class DSN
|
|||
}
|
||||
|
||||
/**
|
||||
* Return the query string
|
||||
* Return the raw query string
|
||||
*
|
||||
* @return ?string
|
||||
*/
|
||||
|
|
|
@ -71,6 +71,39 @@ class DSNTest extends TestCase
|
|||
$this->assertNull($dsn->getPort());
|
||||
$this->assertEmpty($dsn->getDatabase());
|
||||
$this->assertNull($dsn->getQuery());
|
||||
|
||||
$password = 'sl/sh+$@no:her';
|
||||
$encoded = \urlencode($password);
|
||||
$dsn = new DSN("sms://user:$encoded@localhost");
|
||||
$this->assertEquals("sms", $dsn->getScheme());
|
||||
$this->assertEquals("user", $dsn->getUser());
|
||||
$this->assertEquals($password, $dsn->getPassword());
|
||||
$this->assertEquals("localhost", $dsn->getHost());
|
||||
$this->assertNull($dsn->getPort());
|
||||
$this->assertEmpty($dsn->getDatabase());
|
||||
$this->assertNull($dsn->getQuery());
|
||||
|
||||
$user = 'admin@example.com';
|
||||
$encoded = \urlencode($user);
|
||||
$dsn = new DSN("sms://$encoded@localhost");
|
||||
$this->assertEquals("sms", $dsn->getScheme());
|
||||
$this->assertEquals($user, $dsn->getUser());
|
||||
$this->assertNull($dsn->getPassword());
|
||||
$this->assertEquals("localhost", $dsn->getHost());
|
||||
$this->assertNull($dsn->getPort());
|
||||
$this->assertEmpty($dsn->getDatabase());
|
||||
$this->assertNull($dsn->getQuery());
|
||||
|
||||
$value = 'I am 100% value=<complex>, "right"?!';
|
||||
$encoded = \urlencode($value);
|
||||
$dsn = new DSN("sms://localhost?value=$encoded");
|
||||
$this->assertEquals("sms", $dsn->getScheme());
|
||||
$this->assertNull($dsn->getUser());
|
||||
$this->assertNull($dsn->getPassword());
|
||||
$this->assertEquals("localhost", $dsn->getHost());
|
||||
$this->assertNull($dsn->getPort());
|
||||
$this->assertEmpty($dsn->getDatabase());
|
||||
$this->assertEquals("value=$encoded", $dsn->getQuery());
|
||||
}
|
||||
|
||||
public function testFail(): void
|
||||
|
|
Loading…
Reference in a new issue