Skip to content

Commit 3f9c967

Browse files
committed
Improve DSN whitespace parsing
1 parent b636824 commit 3f9c967

2 files changed

Lines changed: 4 additions & 3 deletions

File tree

tests/WP_PDO_MySQL_On_SQLite_PDO_API_Tests.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function test_dsn_parsing(): void {
3030
$this->assertSame( 'wp', $driver->query( 'SELECT DATABASE()' )->fetch()[0] );
3131

3232
// DSN with whitespace before argument names.
33-
$driver = new WP_PDO_MySQL_On_SQLite( "mysql-on-sqlite: path=:memory:;\t dbname=wp" );
33+
$driver = new WP_PDO_MySQL_On_SQLite( "mysql-on-sqlite: path=:memory:; \n\r\t\v\fdbname=wp" );
3434
$this->assertSame( 'wp', $driver->query( 'SELECT DATABASE()' )->fetch()[0] );
3535

3636
// DSN with whitespace in the database name.

wp-includes/sqlite-ast/class-wp-pdo-mysql-on-sqlite.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -623,8 +623,9 @@ public function __construct(
623623
// Restore quoted semicolons that were replaced with "\0".
624624
$arg = str_replace( "\0", ';', $arg );
625625

626-
// PDO DSN allows whitespace before argument name.
627-
$arg = ltrim( $arg );
626+
// PDO DSN allows whitespace before argument name. Trim characters
627+
// as per the "isspace()" C function (in the default "C" locale).
628+
$arg = ltrim( $arg, " \n\r\t\v\f" );
628629

629630
if ( '' === $arg ) {
630631
continue;

0 commit comments

Comments
 (0)