lib/Pico.php
public function resolveFilePath($requestUrl)
    {
        $contentDir = $this->getConfig('content_dir');
        $contentExt = $this->getConfig('content_ext');

        if (!$requestUrl) {
            return $contentDir . 'index' . $contentExt;
        } else {
            // prevent content_dir breakouts
            $requestUrl = str_replace('\\', '/', $requestUrl);
            $requestUrlParts = explode('/', $requestUrl);

            $requestFileParts = array();
            foreach ($requestUrlParts as $requestUrlPart) {
                if (($requestUrlPart === '') || ($requestUrlPart === '.')) {
                    continue;
                } elseif ($requestUrlPart === '..') {
                    array_pop($requestFileParts);
                    continue;
                }

                $requestFileParts[] = $requestUrlPart;
            }

            if (!$requestFileParts) {
                return $contentDir . 'index' . $contentExt;
            }

            // discover the content file to serve
            // Note: $requestFileParts neither contains a trailing nor a leading slash
            $requestFile = $contentDir . implode('/', $requestFileParts);
            if (is_dir($requestFile)) {
                // if no index file is found, try a accordingly named file in the previous dir
                // if this file doesn't exist either, show the 404 page, but assume the index
                // file as being requested (maintains backward compatibility to Pico < 1.0)
                $indexFile = $requestFile . '/index' . $contentExt;
                if (file_exists($indexFile) || !file_exists($requestFile . $contentExt)) {
                    return $indexFile;
                }
            }
            return $requestFile . $contentExt;
        }
    }
public function resolveFilePath($requestUrl)
    {
        $contentDir = $this->getConfig('content_dir');
        $contentExt = $this->getConfig('content_ext');

        if (!$requestUrl) {
            return $contentDir . 'index' . $contentExt;
        } else {
            // prevent content_dir breakouts
            $requestUrl = str_replace('\\', '/', $requestUrl);
            $requestUrlParts = explode('/', $requestUrl);

            $requestFileParts = array();
            foreach ($requestUrlParts as $requestUrlPart) {
                if (($requestUrlPart === '') || ($requestUrlPart === '.')) {
                    continue;
                } elseif ($requestUrlPart === '..') {
                    array_pop($requestFileParts);
                    continue;
                }

                $requestFileParts[] = $requestUrlPart;
            }

            if (!$requestFileParts) {
                return $contentDir . 'index' . $contentExt;
            }

            // discover the content file to serve
            // Note: $requestFileParts neither contains a trailing nor a leading slash
            $requestFile = $contentDir . implode('/', $requestFileParts);
            if (is_dir($requestFile)) {
                // if no index file is found, try a accordingly named file in the previous dir
                // if this file doesn't exist either, show the 404 page, but assume the index
                // file as being requested (maintains backward compatibility to Pico < 1.0)
                $indexFile = $requestFile . '/index' . $contentExt;
                if (file_exists($indexFile) || !file_exists($requestFile . $contentExt)) {
                    return $indexFile;
                }
            }
            return $requestFile . $contentExt;
        }
    }
public function resolveFilePath ( $ requestUrl ) { $ contentDir = $ this -> getConfig ( 'content_dir' ) ; $ contentExt = $ this -> getConfig ( 'content_ext' ) ; if ( ! $ requestUrl ) { return $ contentDir . 'index' . $ contentExt ; } else { // prevent content_dir breakouts $ requestUrl = str_replace ( '\\' , '/' , $ requestUrl ) ; $ requestUrlParts = explode ( '/' , $ requestUrl ) ; $ requestFileParts = array ( ) ; foreach ( $ requestUrlParts as $ requestUrlPart ) { if ( ( $ requestUrlPart === '' ) || ( $ requestUrlPart === '.' ) ) { continue ; } elseif ( $ requestUrlPart === '..' ) { array_pop ( $ requestFileParts ) ; continue ; } $ requestFileParts [ ] = $ requestUrlPart ; } if ( ! $ requestFileParts ) { return $ contentDir . 'index' . $ contentExt ; } // discover the content file to serve // Note: $requestFileParts neither contains a trailing nor a leading slash $ requestFile = $ contentDir . implode ( '/' , $ requestFileParts ) ; if ( is_dir ( $ requestFile ) ) { // if no index file is found, try a accordingly named file in the previous dir // if this file doesn't exist either, show the 404 page, but assume the index // file as being requested (maintains backward compatibility to Pico < 1.0) $ indexFile = $ requestFile . '/index' . $ contentExt ; if ( file_exists ( $ indexFile ) || ! file_exists ( $ requestFile . $ contentExt ) ) { return $ indexFile ; } } return $ requestFile . $ contentExt ; } }
Resolves a given file path to its corresponding content file

This method also prevents `content_dir` breakouts using malicious
request URLs. We don't use `realpath()`, because we neither want to
check for file existance, nor prohibit symlinks which intentionally
point to somewhere outside the `content_dir` folder. It is STRONGLY
RECOMMENDED to use PHP's `open_basedir` feature - always, not just
with Pico!

@see Pico::getRequestFile()

@param string $requestUrl path name (likely from a URL) to resolve

@return string path to the resolved content file
Resolves a given file path to its corresponding content file