Procházet zdrojové kódy

[ZF-9058] Zend_Filter:

- allow encoding to be case-insensitive

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@20905 44c647ce-9c0f-0410-b52a-842ac1e357ba
thomas před 16 roky
rodič
revize
c60e0a518f

+ 1 - 1
library/Zend/Filter/StringToLower.php

@@ -88,7 +88,7 @@ class Zend_Filter_StringToLower implements Zend_Filter_Interface
             }
 
             $encoding = (string) $encoding;
-            if (!in_array($encoding, mb_list_encodings())) {
+            if (!in_array(strtolower($encoding), array_map('strtolower', mb_list_encodings()))) {
                 require_once 'Zend/Filter/Exception.php';
                 throw new Zend_Filter_Exception("The given encoding '$encoding' is not supported by mbstring");
             }

+ 1 - 1
library/Zend/Filter/StringToUpper.php

@@ -88,7 +88,7 @@ class Zend_Filter_StringToUpper implements Zend_Filter_Interface
             }
 
             $encoding = (string) $encoding;
-            if (!in_array($encoding, mb_list_encodings())) {
+            if (!in_array(strtolower($encoding), array_map('strtolower', mb_list_encodings()))) {
                 require_once 'Zend/Filter/Exception.php';
                 throw new Zend_Filter_Exception("The given encoding '$encoding' is not supported by mbstring");
             }

+ 31 - 0
tests/Zend/Filter/StringToLowerTest.php

@@ -138,4 +138,35 @@ class Zend_Filter_StringToLowerTest extends PHPUnit_Framework_TestCase
             $this->assertContains('mbstring is required', $e->getMessage());
         }
     }
+
+    /**
+     * @ZF-9058
+     */
+    public function testCaseInsensitiveEncoding()
+    {
+        $valuesExpected = array(
+            'Ü'     => 'ü',
+            'Ñ'     => 'ñ',
+            'ÜÑ123' => 'üñ123'
+        );
+
+        try {
+            $this->_filter->setEncoding('UTF-8');
+            foreach ($valuesExpected as $input => $output) {
+                $this->assertEquals($output, $this->_filter->filter($input));
+            }
+
+            $this->_filter->setEncoding('utf-8');
+            foreach ($valuesExpected as $input => $output) {
+                $this->assertEquals($output, $this->_filter->filter($input));
+            }
+
+            $this->_filter->setEncoding('UtF-8');
+            foreach ($valuesExpected as $input => $output) {
+                $this->assertEquals($output, $this->_filter->filter($input));
+            }
+        } catch (Zend_Filter_Exception $e) {
+            $this->assertContains('mbstring is required', $e->getMessage());
+        }
+    }
 }

+ 31 - 0
tests/Zend/Filter/StringToUpperTest.php

@@ -138,4 +138,35 @@ class Zend_Filter_StringToUpperTest extends PHPUnit_Framework_TestCase
             $this->assertContains('mbstring is required', $e->getMessage());
         }
     }
+
+    /**
+     *  @ZF-9058
+     */
+    public function testCaseInsensitiveEncoding()
+    {
+        $valuesExpected = array(
+            'ü'     => 'Ü',
+            'ñ'     => 'Ñ',
+            'üñ123' => 'ÜÑ123'
+        );
+
+        try {
+            $this->_filter->setEncoding('UTF-8');
+            foreach ($valuesExpected as $input => $output) {
+                $this->assertEquals($output, $this->_filter->filter($input));
+            }
+
+            $this->_filter->setEncoding('utf-8');
+            foreach ($valuesExpected as $input => $output) {
+                $this->assertEquals($output, $this->_filter->filter($input));
+            }
+
+            $this->_filter->setEncoding('UtF-8');
+            foreach ($valuesExpected as $input => $output) {
+                $this->assertEquals($output, $this->_filter->filter($input));
+            }
+        } catch (Zend_Filter_Exception $e) {
+            $this->assertContains('mbstring is required', $e->getMessage());
+        }
+    }
 }