diff --git a/src/Gitonomy/Git/Util/Credentials.php b/src/Gitonomy/Git/Util/Credentials.php index fbc8719..737019e 100644 --- a/src/Gitonomy/Git/Util/Credentials.php +++ b/src/Gitonomy/Git/Util/Credentials.php @@ -30,7 +30,10 @@ public static function redact(#[\SensitiveParameter] string $text): string { // Up to the last "@" before the host, as a password may hold one, or a // "#" or a "?", which git and libgit2 accept unencoded there. + // Without a scheme too: git prints "user:token@host" when it can't + // resolve the host of a git:// URL. A token alone stays, as nothing + // tells it from the "git@host" of the errors of ssh. // @phpstan-ignore return.type (possessive quantifiers never reach the backtracking limit, and without "u" there is no UTF-8 to fail on) - return preg_replace('#\b([a-z][a-z0-9+.-]*+://)(?:[^/\s@]*+@)++#i', '$1***@', $text); + return preg_replace('#(?:\b([a-z][a-z0-9+.-]*+://)|(? ['https://***@example.com/a.git', 'https://user:p?ss@example.com/a.git']; yield 'several URLs' => ['ssh://***@a.com/x and https://***@b.com/y', 'ssh://git@a.com/x and https://user:password@b.com/y']; yield 'no user information' => ['https://example.com/a@b.git', 'https://example.com/a@b.git']; + yield 'no user information, with a port' => ['https://example.com:8080/a@b.git', 'https://example.com:8080/a@b.git']; yield 'no scheme' => ['git@example.com:a.git', 'git@example.com:a.git']; + yield 'no scheme, the error of ssh' => ['git@example.com: Permission denied (publickey).', 'git@example.com: Permission denied (publickey).']; + yield 'no scheme, an address after a label' => ['Author: jane@example.com', 'Author: jane@example.com']; + yield 'no scheme, the host git prints for a git:// URL' => ['fatal: unable to look up ***@example.com (port 9418)', 'fatal: unable to look up user:password@example.com (port 9418)']; + yield 'no scheme, with a port' => ['unable to look up ***@example.com:9418', 'unable to look up user:password@example.com:9418']; + yield 'no scheme, password holding an "@"' => ['unable to look up ***@example.com', 'unable to look up user:p@ss@example.com']; } /**