浏览代码

Less regex escaping and removed $..$ match, refs #5184

Jordi Boggiano 9 年之前
父节点
当前提交
38c49b32cb
共有 1 个文件被更改,包括 5 次插入5 次删除
  1. 5 5
      src/Composer/Util/Platform.php

+ 5 - 5
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<percent>%))(?P<var>\w++)(?(percent)%)(?P<path>.*)#', 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);
     }