helper function to fix paths '//' or '/./' or '/foo/../' in a path.

@param string $path Path to resolve

@return string
484432
public static function fixPath($path)
    {
        $path = str_replace('\\', '/', $path); //windows paths
        $replace = ['#(/\.?/)#', '#/(?!\.\.)[^/]+/\.\./#'];

        do {
            $path = preg_replace($replace, '/', $path, -1, $n);
        } while ($n > 0);

        return $path;
    }
1329812
protected function normalize_path( $path ) {

		$path = str_replace( '\\', '/', $path );
		$path = preg_replace( '|/+|','/', $path );

		return rtrim( $path, '/' );
	}
763316
public static function resolveUps($path)
    {
        $parts = array();
        foreach (explode('/', $path) as $part) {
            if ('..' === $part && count($parts) && '..' !== end($parts)) {
                array_pop($parts);
            } else {
                $parts[] = $part;
            }
        }

        return implode('/', $parts);
    }
906192
protected function sanitizePath($path)
    {
        if (empty($path)) {
            return '';
        }

        $path = Files::getUnixStylePath($path);
        if (is_dir($path)) {
            $path = Files::getNormalizedPath($path);
        }

        return $path;
    }
971238
public function path($path)
    {
        $path  = strtolower(trim($path));
        $first = substr($path, 0, 1);
        
        if ($first == '@' && isset($this->aliases[$path])) {
            $path = $this->aliases[$path];
            
        } elseif ($first == '/') {
            $path = preg_replace('/\\//', $this->root() . '/', $path, 1);
            
        }
        if ($path = realpath($path)) {
            $path = static::clean($path);
        }
        
        return $path;
    }
413313
protected function _filterPath($path)
    {
        $path = preg_replace_callback(
            '/(?:[^' . self::CHAR_UNRESERVED . ':@&=\+\$,\/;%]+|%(?![A-Fa-f0-9]{2}))/',
            [$this, '_urlEncodeChar'],
            $path
        );

        if (empty($path)) {
            // No path
            return $path;
        }

        if ($path[0] !== '/') {
            // Relative path
            return $path;
        }

        // Ensure only one leading slash, to prevent XSS attempts.
        return '/' . ltrim($path, '/');
    }
644839
protected function makePath($path)
    {
        return $this->context->directory ? $this->context->directory.'/'.$path : $path;
    }
1154163
private function normalizeForFnmatch(string $path): string
    {
        // ends with *
        if (Strings::match($path, '#^[^*](.*?)\*$#')) {
            return '*' . $path;
        }

        // starts with *
        if (Strings::match($path, '#^\*(.*?)[^*]$#')) {
            return $path . '*';
        }

        return $path;
    }
681747
private function filterPath($path)
    {
        if ($path != null && substr($path, 0, 1) !== '/') {
            $path = '/' . $path;
        }

        return preg_replace_callback(
            '/(?:[^' . self::$charUnreserved . ':@&=\+\$,\/;%]+|%(?![A-Fa-f0-9]{2}))/',
            function ($match) { return rawurlencode($match[0]); },
            $path
        );
    }
210192
public static function normalizePath(?string $path): string
  {
    // With thanks to monkeysuffrage, see https://github.com/monkeysuffrage/phpuri/blob/master/phpuri.php.

    if ($path===null || $path==='')
    {
      return '';
    }

    $normalized_path = $path;
    $normalized_path = preg_replace('`//+`', '/', $normalized_path, -1, $c0);
    $normalized_path = preg_replace('`^/\\.\\.?/`', '/', $normalized_path, -1, $c1);
    $normalized_path = preg_replace('`/\\.(/|$)`', '/', $normalized_path, -1, $c2);
    $normalized_path = preg_replace('`/[^/]*?/\\.\\.(/|$)`', '/', $normalized_path, 1, $c3);
    $_num_matches    = $c0 + $c1 + $c2 + $c3;

    return ($_num_matches>0) ? self::normalizePath($normalized_path) : $normalized_path;
  }
1344369
public static function slashPath($path) {
		if (UString::startswith ( $path, "/" ) === false)
			$path = "/" . $path;
		if (! UString::endswith ( $path, "/" ))
			$path = $path . "/";
		return $path;
	}
87538
static public function urlToPath($path)
    {
        $path = parse_url($path);
        return $path === null ? null : str_replace('/', DIRECTORY_SEPARATOR, $path['path']);
    }
1098492
public static function sanitizePath($path)
    {
        while (false !== strpos($path, '..')) {
            $path = str_replace('..', '', $path);
        }

        $path = ('/' !== $path) ? $path : '';

        return $path;
    }
381935
public static function fixCase($path)
    {
        $path = Path::clean($path, DIRECTORY_SEPARATOR);

        $lowerfile = strtolower($path);

        foreach (glob(dirname($path) . DIRECTORY_SEPARATOR . '*') as $file) {
            if (strtolower($file) === $lowerfile) {
                return $file;
            }
        }

        return $path;
    }
1269423
protected static function normalizePath($path)
    {
        $pathAry = explode('/', $path);
        $i       = 1;

        do {
            if ('.' == $pathAry[$i]) {
                if ($i < count($pathAry) - 1) {
                    array_splice($pathAry, $i, 1);
                } else {
                    $pathAry[$i] = '';
                    $i++;
                }

            } elseif ('..' == $pathAry[$i]) {
                if (1 == $i) {
                    array_splice($pathAry, 1, 1);

                } elseif ('..' != $pathAry[$i - 1]) {
                    if ($i < count($pathAry) - 1) {
                        array_splice($pathAry, $i - 1, 2);
                        $i--;
                    } else {
                        array_splice($pathAry, $i - 1, 2, '');
                    }
                }

            } else {
                $i++;
            }
        } while ($i < count($pathAry));

        return implode('/', $pathAry);
    }
372801
protected function fixPath($path)
    {
        $len = strlen($this->front);

        if (substr($path, 0, $len) == $this->front) {
            $path = substr($path, $len);
        }

        return '/' . ltrim($path, '/');
    }
11045
public function compilePath($path)
    {
        if(preg_match_all('/\{(\w+)\}/', $path, $matches, PREG_SET_ORDER) == false)
        {
            return $path;
        }
        else
        {
            foreach($matches as $match)
            {
                $this->params[] = $match[1];
            }

            $static = preg_replace('/\{(\w+)\}/i', "", $path);
            $static = rtrim($static, '/');

            $path = '/' . str_replace('/', '\/', $path) . '/';
            $regex = preg_replace('/\{(\w+)\}/', '(\w+)', $path);

            $this->static_path = $static;
            $this->regex = $regex;
        }

    }