From 2f51144a858fc3e2f2b880ec1ff5d6a541b9e56a Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Sun, 6 Apr 2008 04:00:43 +0000 Subject: [PATCH] Merged revisions 47488 via svnmerge from svn://svn.silverstripe.com/silverstripe/modules/sapphire/branches/2.2.0-mesq ........ r47488 | ischommer | 2007-12-21 16:03:04 +1300 (Fri, 21 Dec 2007) | 1 line in fileExists(): replace any appended query-strings, e.g. /path/to/foo.php?bar=1 to /path/to/foo.php ........ git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@52186 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- core/control/Director.php | 8 ++++++++ tests/control/DirectorTest.php | 25 +++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 tests/control/DirectorTest.php 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