PMCORE-646 Special characters in oracle connection passwords causes bad behavior
This commit is contained in:
@@ -1695,4 +1695,50 @@ class System
|
||||
}
|
||||
return (object) $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse an url with not encoded password that break the native “parse_url” function.
|
||||
* @param string $dsn
|
||||
* @return array
|
||||
*/
|
||||
public static function parseUrlWithNotEncodedPassword(string $dsn): array
|
||||
{
|
||||
$default = [
|
||||
'scheme' => '',
|
||||
'host' => '',
|
||||
'port' => '',
|
||||
'user' => '',
|
||||
'pass' => '',
|
||||
'path' => '',
|
||||
'query' => '',
|
||||
];
|
||||
$separator = "://";
|
||||
$colon = ":";
|
||||
$at = "@";
|
||||
|
||||
$result = explode($separator, $dsn, 2);
|
||||
if (empty($result[0]) || empty($result[1])) {
|
||||
return $default;
|
||||
}
|
||||
$scheme = $result[0];
|
||||
$urlWithoutScheme = $result[1];
|
||||
|
||||
$colonPosition = strpos($urlWithoutScheme, $colon);
|
||||
$user = substr($urlWithoutScheme, 0, $colonPosition);
|
||||
|
||||
$withoutUser = substr($urlWithoutScheme, $colonPosition + 1);
|
||||
$atPosition = strrpos($withoutUser, $at);
|
||||
$pass = substr($urlWithoutScheme, $colonPosition + 1, $atPosition);
|
||||
|
||||
$withoutPass = substr($withoutUser, $atPosition + 1);
|
||||
|
||||
$fixedDsn = $scheme . $separator . $user . $colon . urlencode($pass) . $at . $withoutPass;
|
||||
|
||||
$parseDsn = parse_url($fixedDsn);
|
||||
if ($parseDsn === false) {
|
||||
return $default;
|
||||
}
|
||||
$parseDsn["pass"] = urldecode($parseDsn["pass"]);
|
||||
return $parseDsn;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user