1
0
Fork 0
mirror of synced 2024-07-06 23:21:05 +12:00

Merge pull request #5916 from appwrite/fix-5913-dsn-with-special-chars

Update DSN to support special chars for user and password
This commit is contained in:
Eldad A. Fux 2023-08-01 09:32:11 +03:00 committed by GitHub
commit 264c7bf9a9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 3 deletions

View file

@ -55,8 +55,8 @@ class DSN
} }
$this->scheme = $parts['scheme'] ?? null; $this->scheme = $parts['scheme'] ?? null;
$this->user = $parts['user'] ?? null; $this->user = isset($parts['user']) ? \urldecode($parts['user']) : null;
$this->password = $parts['pass'] ?? null; $this->password = isset($parts['pass']) ? \urldecode($parts['pass']) : null;
$this->host = $parts['host'] ?? null; $this->host = $parts['host'] ?? null;
$this->port = $parts['port'] ?? null; $this->port = $parts['port'] ?? null;
$this->database = $parts['path'] ?? null; $this->database = $parts['path'] ?? null;
@ -124,7 +124,7 @@ class DSN
} }
/** /**
* Return the query string * Return the raw query string
* *
* @return ?string * @return ?string
*/ */

View file

@ -71,6 +71,39 @@ class DSNTest extends TestCase
$this->assertNull($dsn->getPort()); $this->assertNull($dsn->getPort());
$this->assertEmpty($dsn->getDatabase()); $this->assertEmpty($dsn->getDatabase());
$this->assertNull($dsn->getQuery()); $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 public function testFail(): void