diff --git a/core/control/Director.php b/core/control/Director.php index fbea2b682..dc01138f9 100644 --- a/core/control/Director.php +++ b/core/control/Director.php @@ -413,6 +413,12 @@ class Director { /** * Given a filesystem reference relative to the site root, return the full filesystem path */ + /** + * Cleans up a given file-path + * + * @param string $file + * @return string + */ static function getAbsFile($file) { if($file[0] == '/') return $file; return Director::baseFolder() . '/' . $file; @@ -423,6 +429,8 @@ class Director { * @param $file Filename specified relative to the site root */ static function fileExists($file) { + // replace any appended query-strings, e.g. /path/to/foo.php?bar=1 to /path/to/foo.php + $file = preg_replace('/([^\?]*)?.*/','$1',$file); return file_exists(Director::getAbsFile($file)); } diff --git a/tests/control/DirectorTest.php b/tests/control/DirectorTest.php new file mode 100644 index 000000000..0dbe7fbff --- /dev/null +++ b/tests/control/DirectorTest.php @@ -0,0 +1,25 @@ +assertTrue( + Director::fileExists($tempFilePath), + 'File exist check with absolute path' + ); + + $this->assertTrue( + Director::fileExists($tempFilePath . '?queryparams=1&foo[bar]=bar'), + 'File exist check with query params ignored' + ); + + unlink($tempFilePath); + } + +} +?> \ No newline at end of file