Merge pull request #7864 from open-sausages/pulls/4.1/fix-slashes

BUG Fix incorrect convert slashes argument
This commit is contained in:
Daniel Hensby 2018-02-13 10:52:22 +00:00 committed by GitHub
commit 690eec52c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 4 deletions

View File

@ -605,6 +605,6 @@ class Convert
if ($multiple) {
return preg_replace('#[/\\\\]+#', $separator, $path);
}
return str_replace(['/', '\\'], DIRECTORY_SEPARATOR, $path);
return str_replace(['/', '\\'], $separator, $path);
}
}

View File

@ -259,7 +259,7 @@ PHP
/**
* Tests {@link Convert::testRaw2URL()}
*
*
* @todo test toASCII()
*/
public function testRaw2URL()
@ -273,7 +273,7 @@ PHP
/**
* Helper function for comparing characters with significant whitespaces
*
*
* @param string $expected
* @param string $actual
*/
@ -590,7 +590,7 @@ XML
/**
* Test that bytes2memstring returns a binary prefixed string representing the number of bytes
*
* @param string $memString
* @param string $bytes
* @param int $expected
* @dataProvider bytes2MemStringProvider
*/
@ -613,4 +613,40 @@ XML
[(512 * 1024 * 1024 * 1024 * 1024 * 1024), '512P']
];
}
public function providerTestSlashes()
{
return [
['bob/bob', '/', true, 'bob/bob'],
['\\bob/bob\\', '/', true, '/bob/bob/'],
['\\bob////bob\\/', '/', true, '/bob/bob/'],
['bob/bob', '\\', true, 'bob\\bob'],
['\\bob/bob\\', '\\', true, '\\bob\\bob\\'],
['\\bob////bob\\/', '\\', true, '\\bob\\bob\\'],
['bob/bob', '#', true, 'bob#bob'],
['\\bob/bob\\', '#', true, '#bob#bob#'],
['\\bob////bob\\/', '#', true, '#bob#bob#'],
['bob/bob', '/', false, 'bob/bob'],
['\\bob/bob\\', '/', false, '/bob/bob/'],
['\\bob////bob\\/', '/', false, '/bob////bob//'],
['bob/bob', '\\', false, 'bob\\bob'],
['\\bob/bob\\', '\\', false, '\\bob\\bob\\'],
['\\bob////bob\\/', '\\', false, '\\bob\\\\\\\\bob\\\\'],
['bob/bob', '#', false, 'bob#bob'],
['\\bob/bob\\', '#', false, '#bob#bob#'],
['\\bob////bob\\/', '#', false, '#bob####bob##'],
];
}
/**
* @dataProvider providerTestSlashes
* @param string $path
* @param string $separator
* @param bool $multiple
* @param string $expected
*/
public function testSlashes($path, $separator, $multiple, $expected)
{
$this->assertEquals($expected, Convert::slashes($path, $separator, $multiple));
}
}