Skip to content

Commit

Permalink
Merge pull request #2504 from c960657/urldecode-dsn
Browse files Browse the repository at this point in the history
URL-decode URL-style DSN
  • Loading branch information
Ocramius authored Jan 15, 2017
2 parents 4120a72 + cdeb9e8 commit bfecbeb
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
10 changes: 10 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# Upgrade to 2.6

## MINOR BC BREAK: URL-style DSN with percentage sign in password

URL-style DSNs (e.g. ``mysql://foo@bar:localhost/db``) are now assumed to be percent-encoded
in order to allow certain special characters in usernames, paswords and database names. If
you are using a URL-style DSN and have a username, password or database name containing a
percentage sign, you need to update your DSN. If your password is, say, ``foo%foo``, it
should be encoded as ``foo%25foo``.

# Upgrade to 2.5.1

## MINOR BC BREAK: Doctrine\DBAL\Schema\Table
Expand Down
2 changes: 2 additions & 0 deletions lib/Doctrine/DBAL/DriverManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ private static function parseDatabaseUrl(array $params)
throw new DBALException('Malformed parameter "url".');
}

$url = array_map('rawurldecode', $url);

// If we have a connection URL, we have to unset the default PDO instance connection parameter (if any)
// as we cannot merge connection details from the URL into the PDO instance (URL takes precedence).
unset($params['pdo']);
Expand Down
8 changes: 8 additions & 0 deletions tests/Doctrine/Tests/DBAL/DriverManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,14 @@ public function databaseUrls()
'drizzle-pdo-mysql://foo:bar@localhost/baz',
array('user' => 'foo', 'password' => 'bar', 'host' => 'localhost', 'dbname' => 'baz', 'driver' => 'Doctrine\DBAL\Driver\DrizzlePDOMySql\Driver'),
),
'simple URL with percent encoding' => array(
'mysql://foo%3A:bar%2F@localhost/baz+baz%40',
array('user' => 'foo:', 'password' => 'bar/', 'host' => 'localhost', 'dbname' => 'baz+baz@', 'driver' => 'Doctrine\DBAL\Driver\PDOMySQL\Driver'),
),
'simple URL with percent sign in password' => array(
'mysql://foo:bar%25bar@localhost/baz',
array('user' => 'foo', 'password' => 'bar%bar', 'host' => 'localhost', 'dbname' => 'baz', 'driver' => 'Doctrine\DBAL\Driver\PDOMySQL\Driver'),
),

// DBAL-1234
'URL without scheme and without any driver information' => array(
Expand Down

0 comments on commit bfecbeb

Please sign in to comment.