[Pkg-owncloud-commits] [php-sabredav] 19/23: Update Issue 39
David Prévot
taffit at moszumanska.debian.org
Sat Nov 30 15:44:02 UTC 2013
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to tag version-1.0.12
in repository php-sabredav.
commit 0166fa37ae9bd5c362ac74d7c08ccaa3074f3bc7
Author: Evert Pot <evert at rooftopsolutions.nl>
Date: Tue Mar 30 14:14:57 2010 +0900
Update Issue 39
Added splitPath method. This will replace basename and dirname
---
lib/Sabre/DAV/URLUtil.php | 28 ++++++++++++++++++++++++++++
tests/Sabre/DAV/URLUtilTest.php | 34 ++++++++++++++++++++++++++++++++++
2 files changed, 62 insertions(+)
diff --git a/lib/Sabre/DAV/URLUtil.php b/lib/Sabre/DAV/URLUtil.php
index b1b1bad..7af8165 100644
--- a/lib/Sabre/DAV/URLUtil.php
+++ b/lib/Sabre/DAV/URLUtil.php
@@ -112,5 +112,33 @@ class Sabre_DAV_URLUtil {
}
+ /**
+ * Returns the 'dirname' and 'basename' for a path.
+ *
+ * The reason there is a custom function for this purpose, is because
+ * basename() is locale aware (behaviour changes if C locale or a UTF-8 locale is used)
+ * and we need a method that just operates on UTF-8 characters.
+ *
+ * In addition basename and dirname are platform aware, and will treat backslash (\) as a
+ * directory separator on windows.
+ *
+ * This method returns the 2 components as an array.
+ *
+ * If there is no dirname, it will return an empty string. Any / appearing at the end of the
+ * string is stripped off.
+ *
+ * @param string $path
+ * @return array
+ */
+ static function splitPath($path) {
+
+ $matches = array();
+ if(preg_match('/^(?:(?:(.*)(?:\/+))?([^\/]+))(?:\/?)$/u',$path,$matches)) {
+ return array($matches[1],$matches[2]);
+ } else {
+ return array(null,null);
+ }
+
+ }
}
diff --git a/tests/Sabre/DAV/URLUtilTest.php b/tests/Sabre/DAV/URLUtilTest.php
index 97fda5f..afd26a5 100644
--- a/tests/Sabre/DAV/URLUtilTest.php
+++ b/tests/Sabre/DAV/URLUtilTest.php
@@ -91,4 +91,38 @@ class Sabre_DAV_URLUtilTest extends PHPUnit_Framework_TestCase{
}
+ function testSplitPath() {
+
+ $strings = array(
+
+ // input // expected result
+ '/foo/bar' => array('/foo','bar'),
+ '/foo/bar/' => array('/foo','bar'),
+ 'foo/bar/' => array('foo','bar'),
+ 'foo/bar' => array('foo','bar'),
+ 'foo/bar/baz' => array('foo/bar','baz'),
+ 'foo/bar/baz/' => array('foo/bar','baz'),
+ 'foo' => array('','foo'),
+ 'foo/' => array('','foo'),
+ '/foo/' => array('','foo'),
+ '/foo' => array('','foo'),
+
+ // UTF-8
+ "/\xC3\xA0fo\xC3\xB3/bar" => array("/\xC3\xA0fo\xC3\xB3",'bar'),
+ "/\xC3\xA0foo/b\xC3\xBCr/" => array("/\xC3\xA0foo","b\xC3\xBCr"),
+ "foo/\xC3\xA0\xC3\xBCr" => array("foo","\xC3\xA0\xC3\xBCr"),
+
+ );
+
+ foreach($strings as $input => $expected) {
+
+ $output = Sabre_DAV_URLUtil::splitPath($input);
+ $this->assertEquals($expected, $output, 'The expected output for \'' . $input . '\' was incorrect');
+
+
+ }
+
+
+ }
+
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/php-sabredav.git
More information about the Pkg-owncloud-commits
mailing list