From 38aba0406f84dde976856a990d9222384064a6cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Fri, 12 Feb 2016 14:15:56 +0100 Subject: [PATCH 1/3] Use DIRECTORY_SEPARATOR MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The PATH_SEPARATOR is not the right variable... Issue #11944 Signed-off-by: Michal Čihař --- libraries/Error.class.php | 16 ++++++++-------- libraries/php-gettext/gettext.inc | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/libraries/Error.class.php b/libraries/Error.class.php index d9e10cea69..e8d04ed0e9 100644 --- a/libraries/Error.class.php +++ b/libraries/Error.class.php @@ -439,25 +439,25 @@ class PMA_Error extends PMA_Message } $Ahere = explode( - PATH_SEPARATOR, - realpath(__DIR__ . PATH_SEPARATOR . '..') + DIRECTORY_SEPARATOR, + realpath(__DIR__ . DIRECTORY_SEPARATOR . '..') ); - $Adest = explode(PATH_SEPARATOR, $dest); + $Adest = explode(DIRECTORY_SEPARATOR, $dest); $result = '.'; // && count ($Adest)>0 && count($Ahere)>0 ) - while (implode(PATH_SEPARATOR, $Adest) != implode(PATH_SEPARATOR, $Ahere)) { + while (implode(DIRECTORY_SEPARATOR, $Adest) != implode(DIRECTORY_SEPARATOR, $Ahere)) { if (count($Ahere) > count($Adest)) { array_pop($Ahere); - $result .= PATH_SEPARATOR . '..'; + $result .= DIRECTORY_SEPARATOR . '..'; } else { array_pop($Adest); } } - $path = $result . str_replace(implode(PATH_SEPARATOR, $Adest), '', $dest); + $path = $result . str_replace(implode(DIRECTORY_SEPARATOR, $Adest), '', $dest); return str_replace( - PATH_SEPARATOR . PATH_SEPARATOR, - PATH_SEPARATOR, + DIRECTORY_SEPARATOR . PATH_SEPARATOR, + DIRECTORY_SEPARATOR, $path ); } diff --git a/libraries/php-gettext/gettext.inc b/libraries/php-gettext/gettext.inc index 75e2112182..908180d239 100644 --- a/libraries/php-gettext/gettext.inc +++ b/libraries/php-gettext/gettext.inc @@ -244,7 +244,7 @@ function _setlocale($category, $locale) { function _bindtextdomain($domain, $path) { global $text_domains; // ensure $path ends with a slash ('/' should work for both, but lets still play nice) - if (PATH_SEPARATOR == '\\') { + if (DIRECTORY_SEPARATOR == '\\') { if ($path[strlen($path)-1] != '\\' and $path[strlen($path)-1] != '/') $path .= '\\'; } else { From 9d1a5997cb6c2c9a6a2594fce6190fb63c74f53b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Fri, 12 Feb 2016 14:16:43 +0100 Subject: [PATCH 2/3] Correctly handle failing case MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Issue #11953 Signed-off-by: Michal Čihař --- libraries/Error.class.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libraries/Error.class.php b/libraries/Error.class.php index e8d04ed0e9..089cdbf667 100644 --- a/libraries/Error.class.php +++ b/libraries/Error.class.php @@ -425,17 +425,17 @@ class PMA_Error extends PMA_Message * prevent path disclosure in error message, * and make users feel safe to submit error reports * - * @param string $dest path to be shorten + * @param string $path path to be shorten * * @return string shortened path */ - public static function relPath($dest) + public static function relPath($path) { - $dest = @realpath($dest); + $dest = @realpath($path); /* Probably affected by open_basedir */ if ($dest === FALSE) { - return $dest; + return $path; } $Ahere = explode( From 2b3ef7ad99ff2a53a239423cb0485b8b624fdb06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Fri, 12 Feb 2016 14:19:59 +0100 Subject: [PATCH 3/3] Improve test coverage for getting relative path MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michal Čihař --- test/classes/PMA_Error_test.php | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/test/classes/PMA_Error_test.php b/test/classes/PMA_Error_test.php index 2c5d0c1184..6fa0ad21c7 100644 --- a/test/classes/PMA_Error_test.php +++ b/test/classes/PMA_Error_test.php @@ -82,15 +82,26 @@ class PMA_Error_Test extends PHPUnit_Framework_TestCase * Test for setFile * * @return void + * + * @dataProvider filePathProvider */ - public function testSetFile() + public function testSetFile($file, $expected) { - $this->object->setFile('./pma.txt'); - $this->assertStringStartsWith( - implode( - DIRECTORY_SEPARATOR, - array('.', '..', '..') - ), $this->object->getFile() + $this->object->setFile($file); + $this->assertEquals($expected, $this->object->getFile()); + } + + /** + * Data provider for setFile + * + * @return array + */ + public function filePathProvider() + { + return array( + array('./ChangeLog', './ChangeLog'), + array(__FILE__, './test/classes/PMA_Error_test.php'), + array('./NONEXISTING', './NONEXISTING'), ); }