filerepo: always use realpath()
authorAntoine Musso <hashar@users.mediawiki.org>
Mon, 9 Jan 2012 13:40:09 +0000 (13:40 +0000)
committerAntoine Musso <hashar@users.mediawiki.org>
Mon, 9 Jan 2012 13:40:09 +0000 (13:40 +0000)
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

index a0caebe..7a01d9e 100644 (file)
@@ -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() {