BUG Fix incorrect convert slashes argument

This commit is contained in:
Damian Mooyman 2018-02-13 16:29:48 +13:00
parent 833b600018
commit 0b7cf80331
No known key found for this signature in database
GPG Key ID: 78B823A10DE27D1A
2 changed files with 40 additions and 4 deletions

View File

@ -605,6 +605,6 @@ class Convert
if ($multiple) { if ($multiple) {
return preg_replace('#[/\\\\]+#', $separator, $path); 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()} * Tests {@link Convert::testRaw2URL()}
* *
* @todo test toASCII() * @todo test toASCII()
*/ */
public function testRaw2URL() public function testRaw2URL()
@ -273,7 +273,7 @@ PHP
/** /**
* Helper function for comparing characters with significant whitespaces * Helper function for comparing characters with significant whitespaces
* *
* @param string $expected * @param string $expected
* @param string $actual * @param string $actual
*/ */
@ -590,7 +590,7 @@ XML
/** /**
* Test that bytes2memstring returns a binary prefixed string representing the number of bytes * Test that bytes2memstring returns a binary prefixed string representing the number of bytes
* *
* @param string $memString * @param string $bytes
* @param int $expected * @param int $expected
* @dataProvider bytes2MemStringProvider * @dataProvider bytes2MemStringProvider
*/ */
@ -613,4 +613,40 @@ XML
[(512 * 1024 * 1024 * 1024 * 1024 * 1024), '512P'] [(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));
}
} }