Remove ../ to secure path

@param $path
@return string
541819
protected function safePath($path)
    {
        $safePath = '';
        if (dirname($path) !== '.') {
            $safePath = str_replace('../', '', dirname($path)) . '/';
        }
        return $safePath;
    }
590451
private function removeFileExtensionFromPath($path)
    {
        if (strrpos($path, '.') !== false) {
            $path = substr($path, 0, strrpos($path, '.'));
        }

        return $path;
    }
1215751
protected static function removeDotSegments(string $path): string
    {
        $output = '';
        while ($path) {
            if ('..' == $path || '.' == $path) {
                break;
            }
            switch (true) {
                case ('./' == substr($path, 0, 2)):
                    $path = substr($path, 2);
                    break;
                case ('../' == substr($path, 0, 3)):
                    $path = substr($path, 3);
                    break;
                case ('/./' == substr($path, 0, 3)):
                    $path = substr($path, 2);
                    break;
                case ('/../' == substr($path, 0, 4)):
                    $path = '/'.substr($path, 4);
                    $pos = strrpos($output, '/', -1);
                    if ($pos !== false) {
                        $output = substr($output, 0, $pos);
                    }
                    break;
                case ('/..' == substr($path, 0, 3) && (in_array(substr($path, 3, 1), [false, '', '/'], true))):
                    $path = '/'.substr($path, 3);
                    $pos = strrpos($output, '/', -1);
                    if ($pos !== false) {
                        $output = substr($output, 0, $pos);
                    }
                    break;
                case ('/.' == substr($path, 0, 2) && (in_array(substr($path, 2, 1), [false, '', '/'], true))):
                    $path = '/'.substr($path, 2);
                    break;
                default:
                    $nextSlash = strpos($path, '/', 1);
                    if (false === $nextSlash) {
                        $segment = $path;
                    } else {
                        $segment = substr($path, 0, $nextSlash);
                    }
                    $output .= $segment;
                    $path = substr($path, strlen($segment));
                    break;
            }
        }

        return $output;
    }
900021
public function delete( $path = '' )
    {
        if ( empty( $path ) ) {
            $this->_value = [];
        }
        else {
            $path = str_replace( '/', '.', $path );
            $keys = explode( ".", $path );

            $lastKey = $keys[ count( $keys ) - 1 ];

            $array = &$this->_value;

            foreach ( $keys as $key ) {
                if ( $key == $lastKey ) {
                    unset( $array[ $key ] );
                    break;
                }
                $array = &$array[ $key ];
            }
        }
        $result = WpOption::updateOrCreate(
            ['option_name' => $this->optionsName],
            ['option_value' => json_encode( $this->_value )]
        );

        return $this->_value;
    }
1081794
public function remove( $path )
    {
        if ( null === $this->identity )
        {
            return false;
        }

        if ( is_array( $path ) || is_object( $path ) )
        {
            $result = array();

            foreach ( $path as $key => $p )
            {
                $result[$key] = $this->remove( $p );
            }

            return $result;
        }

        $path = $this->realPath( $path );
        $base = $this->baseUrl . ( empty( $path ) ? '' : '/' . $path );
        $full = realpath( $this->baseDir . '/' . $base );

        if ( empty( $path ) ) // prevent delete root
        {
            return false;
        }

        $isDir  = is_dir( $full );
        $isFile = is_file( $full );

        if ( $isDir || $isFile )
        {
            $rights = $this->rights( $path );

            if ( $rights->delete )
            {
                switch ( true )
                {
                    case $isDir:
                        return $this->_rmdir( $full );

                    case $isFile:
                        return @ unlink( $full );
                }
            }
        }

        return false;
    }
106424
public static function stripQueryString($path)
    {
        $qMark = strpos($path, '?');

        if ($qMark !== false) {
            return substr($path, 0, $qMark);
        }

        return $path;
    }
271172
public static function cleanPath($path)
    {
        $regex = '/(\/)\/+/';
        $path = str_replace(['\\', '/ /'], '/', $path);
        $path = preg_replace($regex,'$1',$path);

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

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

		return rtrim( $path, '/' );
	}
119654
private function removeBasePath(string $path)
    {
        if (\strpos($path, $this->basePath) === 0) {
            $path = \substr($path, \strlen($this->basePath)) ?: '';
        }

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

        return $path;
    }
1344369
public static function slashPath($path) {
		if (UString::startswith ( $path, "/" ) === false)
			$path = "/" . $path;
		if (! UString::endswith ( $path, "/" ))
			$path = $path . "/";
		return $path;
	}
1034498
public final function clean_path($path) {

        $path = rtrim($path, DIRECTORY_SEPARATOR);

        $parttoremove = DIRECTORY_SEPARATOR . 'tests';

        $substr = substr($path, strlen($path) - strlen($parttoremove));
        if ($substr == $parttoremove) {
            $path = substr($path, 0, strlen($path) - strlen($parttoremove));
        }

        return rtrim($path, DIRECTORY_SEPARATOR);
    }
1347406
protected function cleanPath($path)
    {
        $path    = str_replace('\\', '/', $path);
        $path    = explode('/', $path);
        $newpath = array();
        foreach ($path as $p) {
            if ($p === '' || $p === '.') {
                continue;
            }
            if ($p === '..') {
                array_pop($newpath);
                continue;
            }
            array_push($newpath, $p);
        }
        return trim(implode('/', $newpath), '/');
    }
1202267
protected function _relpath($path) {
		return $path == $this->root ? '' : substr($path, strlen($this->root)+1);
	}
1212457
public static function remove($path)
    {
        $path = Normalize::diskFullPath($path);

        if (!self::exist($path)) {
            return false;
        }
        return unlink($path);
    }
1332184
protected function normalizePath($path)
    {
        if (preg_match("/^id:.*|^rev:.*|^(ns:[0-9]+(\/.*)?)/", $path) === 1) {
            return $path;
        }

        $path = (trim($path, '/') === '') ? '' : '/'.$path;

        return str_replace('//', '/', $path);
    }
1093368
function removeBrokenLinksAt($path)
    {
        collect($this->scandir($path))
                ->filter(function ($file) use ($path) {
                    return $this->isBrokenLink($path.'/'.$file);
                })
                ->each(function ($file) use ($path) {
                    $this->unlink($path.'/'.$file);
                });
    }
1276391
public function remove($path)
    {
        $keys       = $this->explode($path);
        $parameters = &$this->parameters;

        while (count($keys) > 0) {
            if (count($keys) === 1) {
                if (is_array($parameters)) {
                    unset($parameters[array_shift($keys)]);
                } else {
                    return $this;
                }
            } else {
                $key = array_shift($keys);

                if (!isset($parameters[$key])) {
                    return $this;
                }
                $parameters = &$parameters[$key];
            }
        }
        return $this;
    }