[Pkg-owncloud-commits] [php-sabredav] 10/23: Normalizing latin1 encoding to utf-8
David Prévot
taffit at moszumanska.debian.org
Sat Nov 30 15:44:01 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 744980aefffbeb6821caf9b78e5693901cb01e09
Author: Evert Pot <evert at rooftopsolutions.nl>
Date: Fri Mar 26 23:22:44 2010 +0900
Normalizing latin1 encoding to utf-8
---
lib/Sabre/DAV/URLUtil.php | 18 ++++++++++++------
tests/Sabre/DAV/URLUtilTest.php | 29 +++++++++++++++++++++++++++++
2 files changed, 41 insertions(+), 6 deletions(-)
diff --git a/lib/Sabre/DAV/URLUtil.php b/lib/Sabre/DAV/URLUtil.php
index 60740e7..94e21ce 100644
--- a/lib/Sabre/DAV/URLUtil.php
+++ b/lib/Sabre/DAV/URLUtil.php
@@ -82,28 +82,34 @@ class Sabre_DAV_URLUtil {
/**
* Decodes a url-encoded path
*
- * It should be noted that this method just uses php's urldecode.
- *
* @param string $path
* @return string
*/
static function decodePath($path) {
- return urldecode($path);
+ return self::decodePathSegment($path);
}
/**
* Decodes a url-encoded path segment
*
- * It should be noted that this method just uses php's urldecode.
- *
* @param string $path
* @return string
*/
static function decodePathSegment($path) {
- return urldecode($path);
+ $path = urldecode($path);
+ $encoding = mb_detect_encoding($path, array('UTF-8','ISO-8859-1'));
+ switch($encoding) {
+
+ case 'UTF-8' :
+ return $path;
+ case 'ISO-8859-1' :
+ return utf8_encode($path);
+ default :
+ throw new Sabre_DAV_Exception_BadRequest('Invalid url encoding');
+ }
}
diff --git a/tests/Sabre/DAV/URLUtilTest.php b/tests/Sabre/DAV/URLUtilTest.php
index b0557d7..e3c7de2 100644
--- a/tests/Sabre/DAV/URLUtilTest.php
+++ b/tests/Sabre/DAV/URLUtilTest.php
@@ -48,5 +48,34 @@ class Sabre_DAV_URLUtilTest extends PHPUnit_Framework_TestCase{
}
+ function testDecode() {
+
+ $str = 'Hello%20Test+Test2.txt';
+ $newStr = Sabre_DAV_URLUtil::decodePath($str);
+ $this->assertEquals('Hello Test Test2.txt',$newStr);
+
+ }
+
+ /**
+ * @depends testDecode
+ */
+ function testDecodeUmlaut() {
+
+ $str = 'Hello%C3%BC.txt';
+ $newStr = Sabre_DAV_URLUtil::decodePath($str);
+ $this->assertEquals("Hello\xC3\xBC.txt",$newStr);
+
+ }
+
+ /**
+ * @depends testDecodeUmlaut
+ */
+ function testDecodeUmlautLatin1() {
+
+ $str = 'Hello%FC.txt';
+ $newStr = Sabre_DAV_URLUtil::decodePath($str);
+ $this->assertEquals("Hello\xC3\xBC.txt",$newStr);
+
+ }
}
--
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