diff options
| author | Nathan Guse <nathaniel.guse@gmail.com> | 2013-09-12 10:25:49 -0500 | 
|---|---|---|
| committer | Nathan Guse <nathaniel.guse@gmail.com> | 2013-09-12 10:25:49 -0500 | 
| commit | b06c8a80d15c52dd53b12065d5e6e9d56f203ceb (patch) | |
| tree | 15cb3142b27632f60b0ff9c9159412f69a0765ce | |
| parent | 3a4efa79592616ac099e95d07e9aed52bc5a19a3 (diff) | |
| download | forums-b06c8a80d15c52dd53b12065d5e6e9d56f203ceb.tar forums-b06c8a80d15c52dd53b12065d5e6e9d56f203ceb.tar.gz forums-b06c8a80d15c52dd53b12065d5e6e9d56f203ceb.tar.bz2 forums-b06c8a80d15c52dd53b12065d5e6e9d56f203ceb.tar.xz forums-b06c8a80d15c52dd53b12065d5e6e9d56f203ceb.zip | |
[ticket/11832] Fix the web path corrections
Add some real life examples to test
PHPBB3-11832
| -rw-r--r-- | phpBB/phpbb/filesystem.php | 44 | ||||
| -rw-r--r-- | tests/filesystem/web_root_path_test.php | 13 | 
2 files changed, 45 insertions, 12 deletions
| diff --git a/phpBB/phpbb/filesystem.php b/phpBB/phpbb/filesystem.php index 6c037b2656..a2dfab40e5 100644 --- a/phpBB/phpbb/filesystem.php +++ b/phpBB/phpbb/filesystem.php @@ -90,25 +90,49 @@ class phpbb_filesystem  			return $this->web_root_path;  		} -		$path_info = $symfony_request->getPathInfo(); +		// Path info (e.g. /foo/bar) +		$path_info = $this->clean_path($symfony_request->getPathInfo()); + +		// Full request URI (e.g. phpBB/index.php/foo/bar) +		$request_uri = $symfony_request->getRequestUri(); + +		// Script name URI (e.g. phpBB/index.php) +		$script_name = $symfony_request->getScriptName(); + +		/* +		* If the path info is empty (single /), then we're not using +		*	a route like index.php/foo/bar +		*/  		if ($path_info === '/')  		{  			return $this->web_root_path = $this->phpbb_root_path;  		} -		$path_info = $this->clean_path($path_info); - -		// Do not count / at start of path -		$corrections = substr_count(substr($path_info, 1), '/'); +		// How many corrections might we need? +		$corrections = substr_count($path_info, '/'); -		// When URL Rewriting is enabled, app.php is optional. We have to -		// correct for it not being there -		if (strpos($symfony_request->getRequestUri(), $symfony_request->getScriptName()) === false) +		/* +		* If the script name (e.g. phpBB/app.php) exists in the +		*	requestUri (e.g. phpBB/app.php/foo/template), then we +		*	are have a non-rewritten URL. +		*/ +		if (strpos($request_uri, $script_name) === 0)  		{ -			$corrections -= 1; +			/* +			* Append ../ to the end of the phpbb_root_path as many times +			*	as / exists in path_info +			*/ +			return $this->web_root_path = $this->phpbb_root_path . str_repeat('../', $corrections);  		} -		return $this->web_root_path = $this->phpbb_root_path . str_repeat('../', $corrections); +		/* +		* If we're here it means we're at a re-written path, so we must +		*	correct the relative path for web URLs. We must append ../ +		*	to the end of the root path as many times as / exists in path_info +		*	less one time (because the script, e.g. /app.php, doesn't exist in +		*	the URL) +		*/ +		return $this->web_root_path = $this->phpbb_root_path . str_repeat('../', $corrections - 1);  	}  	/** diff --git a/tests/filesystem/web_root_path_test.php b/tests/filesystem/web_root_path_test.php index badc2fab58..8e0ba278e0 100644 --- a/tests/filesystem/web_root_path_test.php +++ b/tests/filesystem/web_root_path_test.php @@ -62,7 +62,7 @@ class phpbb_filesystem_web_root_path_test extends phpbb_test_case  			),  			array(  				$this->phpbb_root_path . 'test.php', -				$this->phpbb_root_path . 'test.php', +				$this->phpbb_root_path . '../test.php',  				'//',  			),  			array( @@ -75,7 +75,16 @@ class phpbb_filesystem_web_root_path_test extends phpbb_test_case  			array(  				$this->phpbb_root_path . 'test.php',  				$this->phpbb_root_path . '../../test.php', -				'////', +				'/foo/template', +				'/phpbb3-fork/phpBB/app.php/foo/template', +				'/phpbb3-fork/phpBB/app.php', +			), +			array( +				$this->phpbb_root_path . 'test.php', +				$this->phpbb_root_path . '../test.php', +				'/foo/template', +				'/phpbb3-fork/phpBB/foo/template', +				'/phpbb3-fork/phpBB/app.php',  			),  		);  	} | 
