From 38c49b32cba28b438868d8ee4d76de49cb6b8779 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Fri, 22 Apr 2016 20:48:56 +0100 Subject: [PATCH] Less regex escaping and removed $..$ match, refs #5184 --- src/Composer/Util/Platform.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Composer/Util/Platform.php b/src/Composer/Util/Platform.php index 1b2b4031f..0fdfc1a10 100644 --- a/src/Composer/Util/Platform.php +++ b/src/Composer/Util/Platform.php @@ -27,15 +27,15 @@ class Platform */ public static function expandPath($path) { - if (preg_match('#^~[/\\\\]#', $path)) { + if (preg_match('#^~[\\/]#', $path)) { return self::getUserDirectory() . substr($path, 1); } - return preg_replace_callback('#^([\\$%])(\\w+)\\1?(([/\\\\].*)?)#', function($matches) { + return preg_replace_callback('#^(\$|(?P%))(?P\w++)(?(percent)%)(?P.*)#', function($matches) { // Treat HOME as an alias for USERPROFILE on Windows for legacy reasons - if (Platform::isWindows() && $matches[2] == 'HOME') { - return (getenv('HOME') ?: getenv('USERPROFILE')) . $matches[3]; + if (Platform::isWindows() && $matches['var'] == 'HOME') { + return (getenv('HOME') ?: getenv('USERPROFILE')) . $matches['path']; } - return getenv($matches[2]) . $matches[3]; + return getenv($matches['var']) . $matches['path']; }, $path); }