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:
commit
264c7bf9a9
2 changed files with 36 additions and 3 deletions
|
@ -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
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue