Merge branch 'QA_4_6'

This commit is contained in:
Michal Čihař 2016-02-12 14:25:32 +01:00
commit 4d00b58fa2
3 changed files with 31 additions and 20 deletions

View File

@ -412,39 +412,39 @@ class Error extends 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(
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
);
}

View File

@ -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 {

View File

@ -81,15 +81,26 @@ class ErrorTest extends PMATestCase
* 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'),
);
}