From 42dee711d89daf338ae6c6898d6e951a274f6d37 Mon Sep 17 00:00:00 2001 From: Antoine Musso Date: Mon, 9 Jan 2012 13:40:09 +0000 Subject: [PATCH] filerepo: always use realpath() The suffix to strip was determined using realpath() but applied on the given path. This could lead to errors when the path is made of a symbolic link or use consecutives slashes. Example on Mac OS: $ php -a php > print realpath( '/private///tmp' ); /private/tmp php > print realpath( '///tmp///////' ); /private/tmp php > $ Fix FileBackendTest::testGetFileList test which failed with: 1) FileBackendTest::testGetFileList Correct file listing (FSFileBackend). Failed asserting that two arrays are equal. --- Expected +++ Actual @@ @@ Array ( - 0 => 'subdir1/test1.txt' - 1 => 'subdir1/test2.txt' - 2 => 'subdir2/subdir/sub/120-px-file.txt' - 3 => 'subdir2/subdir/sub/test0.txt' - 4 => 'subdir2/subdir/test1.txt' - 5 => 'subdir2/subdir/test2.txt' - 6 => 'subdir2/subdir/test3.txt' - 7 => 'subdir2/subdir/test4.txt' - 8 => 'subdir2/subdir/test5.txt' - 9 => 'subdir2/test3.txt' - 10 => 'subdir2/test4.txt' - 11 => 'test1.txt' - 12 => 'test2.txt' - 13 => 'test3.txt' + 0 => '/subdir/sub/120-px-file.txt' + 1 => '/subdir/sub/test0.txt' + 2 => '/subdir/test1.txt' + 3 => '/subdir/test2.txt' + 4 => '/subdir/test3.txt' + 5 => '/subdir/test4.txt' + 6 => '/subdir/test5.txt' + 7 => '/test1.txt' + 8 => '/test2.txt' + 9 => '/test3.txt' + 10 => '/test4.txt' + 11 => 'xt' + 12 => 'xt' + 13 => 'xt' ) --- includes/filerepo/backend/FSFileBackend.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/includes/filerepo/backend/FSFileBackend.php b/includes/filerepo/backend/FSFileBackend.php index a0caebea8d..7a01d9e5aa 100644 --- a/includes/filerepo/backend/FSFileBackend.php +++ b/includes/filerepo/backend/FSFileBackend.php @@ -469,7 +469,8 @@ class FSFileIterator implements Iterator { public function current() { // Return only the relative path and normalize slashes to FileBackend-style - return str_replace( '\\', '/', substr( $this->iter->current(), $this->suffixStart ) ); + // Make sure to use the realpath since the suffix is based upon that + return str_replace( '\\', '/', substr( realpath($this->iter->current()), $this->suffixStart ) ); } public function key() { -- 2.20.1