r108408 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r108407‎ | r108408 | r108409 >
Date:13:40, 9 January 2012
Author:hashar
Status:ok (Comments)
Tags:
Comment:
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'
)
Modified paths:
  • /trunk/phase3/includes/filerepo/backend/FSFileBackend.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/filerepo/backend/FSFileBackend.php
@@ -469,7 +469,8 @@
470470
471471 public function current() {
472472 // Return only the relative path and normalize slashes to FileBackend-style
473 - return str_replace( '\\', '/', substr( $this->iter->current(), $this->suffixStart ) );
 473+ // Make sure to use the realpath since the suffix is based upon that
 474+ return str_replace( '\\', '/', substr( realpath($this->iter->current()), $this->suffixStart ) );
474475 }
475476
476477 public function key() {

Sign-offs

UserFlagDate
😂inspected13:43, 9 January 2012
😂tested13:43, 9 January 2012

Comments

#Comment by 😂 (talk | contribs)   13:43, 9 January 2012

Thank you!

#Comment by Aaron Schulz (talk | contribs)   22:41, 11 January 2012

I thought the results returned already were real. Interesting.

Status & tagging log