From 0b7cf8033198077cf6594f91e3f816d562cabc50 Mon Sep 17 00:00:00 2001 From: Damian Mooyman Date: Tue, 13 Feb 2018 16:29:48 +1300 Subject: [PATCH] BUG Fix incorrect convert slashes argument --- src/Core/Convert.php | 2 +- tests/php/Core/ConvertTest.php | 42 +++++++++++++++++++++++++++++++--- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/src/Core/Convert.php b/src/Core/Convert.php index 277acf4d8..45b8d4df9 100644 --- a/src/Core/Convert.php +++ b/src/Core/Convert.php @@ -605,6 +605,6 @@ class Convert if ($multiple) { return preg_replace('#[/\\\\]+#', $separator, $path); } - return str_replace(['/', '\\'], DIRECTORY_SEPARATOR, $path); + return str_replace(['/', '\\'], $separator, $path); } } diff --git a/tests/php/Core/ConvertTest.php b/tests/php/Core/ConvertTest.php index e92f65330..f435e1eb0 100644 --- a/tests/php/Core/ConvertTest.php +++ b/tests/php/Core/ConvertTest.php @@ -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)); + } }