Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Messenger] Allow password in redis dsn when using sockets #47475

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Improve
  • Loading branch information
PhilETaylor committed Sep 2, 2022
commit ff29ec352e2d4c48439c814a76e9c3a65175b249
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,12 @@ private static function parseDsn(string $dsn, array &$redisOptions): array
$url = $dsn;
$scheme = 0 === strpos($dsn, 'rediss:') ? 'rediss' : 'redis';

// if scheme:///...
PhilETaylor marked this conversation as resolved.
Show resolved Hide resolved
if (preg_match('#^'.$scheme.':///([^:@])+$#', $dsn)) {
$url = str_replace($scheme.':', 'file:', $dsn);
}

// if scheme://...
PhilETaylor marked this conversation as resolved.
Show resolved Hide resolved
$url = preg_replace_callback('#^'.$scheme.':(//)?(?:(?:(?<user>[^:@]*+):)?(?<password>[^@]*+)@)?#', function ($m) use (&$auth) {
if (isset($m['password'])) {
if (!\in_array($m['user'], ['', 'default'], true)) {
Expand All @@ -287,20 +289,21 @@ private static function parseDsn(string $dsn, array &$redisOptions): array

$auth['pass'] = $m['password'];
}

return 'file:'.($m[1] ?? '');
}, $url);

if (false === $parsedUrl = parse_url($url)) {
throw new InvalidArgumentException(sprintf('The given Redis DSN "%s" is invalid.', $dsn));
}

$parsedUrl = $parsedUrl + ($auth ?? []);
if ($auth !== null) {
unset($parsedUrl['user']); // parse_url thinks //0@localhost/ is a password of "0"! doh!
$parsedUrl = $parsedUrl + ($auth ?? []); // But don't worry as $auth array will have user, user/pass or pass as needed
PhilETaylor marked this conversation as resolved.
Show resolved Hide resolved
}

if (\array_key_exists('host', $parsedUrl)) {
$parsedUrl = ['scheme' => $scheme, 'host' => $parsedUrl['host'], 'port' => $parsedUrl['port'] ?? '6379'] + $parsedUrl;
} else {
$parsedUrl = ['scheme' => 'unix', 'path' => $parsedUrl['path']] + $parsedUrl;
// revert scheme now we are finished using PHP parse_url
if ($parsedUrl['scheme'] == 'file') {
$parsedUrl['scheme'] = $scheme;
}

if (isset($parsedUrl['query'])) {
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.