From 288e19153d5b144e1b7c731d7065da3141a66aae Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Sat, 5 Jun 2021 15:58:55 +0200 Subject: [PATCH] Alternative fix for #9941 to avoid code duplication --- src/Composer/Util/Url.php | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/src/Composer/Util/Url.php b/src/Composer/Util/Url.php index a018f97b7..26cf80f9b 100644 --- a/src/Composer/Util/Url.php +++ b/src/Composer/Util/Url.php @@ -109,25 +109,13 @@ class Url // e.g. https://api.github.com/repositories/9999999999?access_token=github_token $url = preg_replace('{([&?]access_token=)[^&]+}', '$1***', $url); - // duplication here to apparent PCRE regression in v10.37 26-May-2021 which - // makes (?P://|^) not match anymore - // should be reverted ideally when fixed in upstream - $url = preg_replace_callback('{^(?P[^:/\s@]+):(?P[^@\s/]+)@}i', function ($m) { + $url = preg_replace_callback('{^(?P[a-z0-9]+://)?(?P[^:/\s@]+):(?P[^@\s/]+)@}i', function ($m) { // if the username looks like a long (12char+) hex string, or a modern github token (e.g. gp1_xxx) we obfuscate that if (preg_match('{^([a-f0-9]{12,}|g[a-z]\d_[a-zA-Z0-9_]+)$}', $m['user'])) { - return '***:***@'; + return $m['prefix'].'***:***@'; } - return $m['user'].':***@'; - }, $url); - - $url = preg_replace_callback('{://(?P[^:/\s@]+):(?P[^@\s/]+)@}i', function ($m) { - // if the username looks like a long (12char+) hex string, or a modern github token (e.g. gp1_xxx) we obfuscate that - if (preg_match('{^([a-f0-9]{12,}|g[a-z]\d_[a-zA-Z0-9_]+)$}', $m['user'])) { - return '://***:***@'; - } - - return '://'.$m['user'].':***@'; + return $m['prefix'].$m['user'].':***@'; }, $url); return $url;