1
0
Fork 0

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

pull/5238/head
Jordi Boggiano 2016-04-22 20:48:56 +01:00
parent d8c94c2640
commit 38c49b32cb
1 changed files with 5 additions and 5 deletions

View File

@ -27,15 +27,15 @@ class Platform
*/ */
public static function expandPath($path) public static function expandPath($path)
{ {
if (preg_match('#^~[/\\\\]#', $path)) { if (preg_match('#^~[\\/]#', $path)) {
return self::getUserDirectory() . substr($path, 1); 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 // Treat HOME as an alias for USERPROFILE on Windows for legacy reasons
if (Platform::isWindows() && $matches[2] == 'HOME') { if (Platform::isWindows() && $matches['var'] == 'HOME') {
return (getenv('HOME') ?: getenv('USERPROFILE')) . $matches[3]; return (getenv('HOME') ?: getenv('USERPROFILE')) . $matches['path'];
} }
return getenv($matches[2]) . $matches[3]; return getenv($matches['var']) . $matches['path'];
}, $path); }, $path);
} }