diff --git a/libraries/joomla/filesystem/path.php b/libraries/joomla/filesystem/path.php index 1029ca8c7d..0cb3ce1eb8 100644 --- a/libraries/joomla/filesystem/path.php +++ b/libraries/joomla/filesystem/path.php @@ -200,9 +200,14 @@ public static function clean($path, $ds = DIRECTORY_SEPARATOR) { $path = JPATH_ROOT; } + // Remove double slashes and backslashes and convert all slashes and backslashes to DIRECTORY_SEPARATOR + // If dealing with a UNC path don't forget to prepend the path with a backslash. + elseif (($ds == '\\') && ($path[0] == '\\' ) && ( $path[1] == '\\' )) + { + $path = "\\" . preg_replace('#[/\\\\]+#', $ds, $path); + } else { - // Remove double slashes and backslashes and convert all slashes and backslashes to DIRECTORY_SEPARATOR $path = preg_replace('#[/\\\\]+#', $ds, $path); } diff --git a/tests/suites/unit/joomla/filesystem/JPathTest.php b/tests/suites/unit/joomla/filesystem/JPathTest.php index 5325961298..912df90d05 100644 --- a/tests/suites/unit/joomla/filesystem/JPathTest.php +++ b/tests/suites/unit/joomla/filesystem/JPathTest.php @@ -1,110 +1,112 @@ object = new JPath; - } +class JPathTest extends TestCase +{ + /** + * Data provider for testClean() method. + * + * @return array + * + * @since 12.2 + */ + public function getCleanData() + { + return array( + // Input Path, Directory Separator, Expected Output + 'Nothing to do.' => array('/var/www/foo/bar/baz', '/', '/var/www/foo/bar/baz'), + 'One backslash.' => array('/var/www/foo\\bar/baz', '/', '/var/www/foo/bar/baz'), + 'Two and one backslashes.' => array('/var/www\\\\foo\\bar/baz', '/', '/var/www/foo/bar/baz'), + 'Mixed backslashes and double forward slashes.' => array('/var\\/www//foo\\bar/baz', '/', '/var/www/foo/bar/baz'), + 'UNC path.' => array('\\\\www\\docroot', '\\', '\\\\www\\docroot'), + 'UNC path with forward slash.' => array('\\\\www/docroot', '\\', '\\\\www\\docroot'), + 'UNC path with UNIX directory separator.' => array('\\\\www/docroot', '/', '/www/docroot'), + ); + } - /** - * Tears down the fixture, for example, closes a network connection. - * This method is called after a test is executed. - */ - protected function tearDown() { - - } - - /** + /** * @todo Implement testCanChmod(). */ - public function testCanChmod() { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } + public function testCanChmod() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete('This test has not been implemented yet.'); + } - /** + /** * @todo Implement testSetPermissions(). */ - public function testSetPermissions() { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } + public function testSetPermissions() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete('This test has not been implemented yet.'); + } - /** + /** * @todo Implement testGetPermissions(). */ - public function testGetPermissions() { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } + public function testGetPermissions() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete('This test has not been implemented yet.'); + } - /** + /** * @todo Implement testCheck(). */ - public function testCheck() { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } + public function testCheck() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete('This test has not been implemented yet.'); + } - /** - * @todo Implement testClean(). - */ - public function testClean() { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } + /** + * Tests the clean method. + * + * @return void + * + * @covers JPath::clean + * @dataProvider getCleanData + * @since 12.2 + */ + public function testClean($input, $ds, $expected) + { + $this->assertEquals( + $expected, + JPath::clean($input, $ds) + ); + } - /** + /** * @todo Implement testIsOwner(). */ - public function testIsOwner() { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } + public function testIsOwner() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete('This test has not been implemented yet.'); + } - /** + /** * @todo Implement testFind(). */ - public function testFind() { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - + public function testFind() + { + // Remove the following lines when you implement this test. + $this->markTestIncomplete('This test has not been implemented yet.'); + } } - -?>