Ver Fonte

[ZF-8828] Zend_Filter_StripTags:

- ensure ISO encoded strings are not stripped with comments

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@20308 44c647ce-9c0f-0410-b52a-842ac1e357ba
thomas há 16 anos atrás
pai
commit
3167362211
2 ficheiros alterados com 33 adições e 4 exclusões
  1. 1 2
      library/Zend/Filter/StripTags.php
  2. 32 2
      tests/Zend/Filter/StripTagsTest.php

+ 1 - 2
library/Zend/Filter/StripTags.php

@@ -1,5 +1,4 @@
 <?php
-
 /**
  * Zend Framework
  *
@@ -238,7 +237,7 @@ class Zend_Filter_StripTags implements Zend_Filter_Interface
     public function filter($value)
     {
         // Strip HTML comments first
-        $valueCopy = preg_replace('#<!--(?:[^<]+|<(?!\!--))*?(--\s*>)#us', '', (string) $value);
+        $valueCopy = preg_replace('#<!--(?:[^<]+|<(?!\!--))*?(--\s*>)#s', '', (string) $value);
 
         // Initialize accumulator for filtered data
         $dataFiltered = '';

+ 32 - 2
tests/Zend/Filter/StripTagsTest.php

@@ -433,8 +433,8 @@ class Zend_Filter_StripTagsTest extends PHPUnit_Framework_TestCase
     }
 
     /**
-     * Ensures expected behavior when comments are marked as allowed (in our 
-     * case, this should have no effect) and a comment contains tags and 
+     * Ensures expected behavior when comments are marked as allowed (in our
+     * case, this should have no effect) and a comment contains tags and
      * linebreaks
      *
      * @group ZF-8473
@@ -523,6 +523,36 @@ class Zend_Filter_StripTagsTest extends PHPUnit_Framework_TestCase
         $filtered = $this->_filter->filter($input);
         $this->assertNotContains('onclick', $filtered);
     }
+
+    /**
+     * @ZF-8828
+     */
+    public function testFilterIsoChars()
+    {
+        $input    = 'äöü<!-- a comment -->äöü';
+        $expected = 'äöüäöü';
+        $this->assertEquals($expected, $this->_filter->filter($input));
+
+        $input    = 'äöü<!-- a comment -->äöü';
+        $input    = iconv("UTF-8", "ISO-8859-1", $input);
+        $output   = $this->_filter->filter($input);
+        $this->assertFalse(empty($output));
+    }
+
+    /**
+     * @ZF-8828
+     */
+    public function testFilterIsoCharsInComment()
+    {
+        $input    = 'äöü<!--üßüßüß-->äöü';
+        $expected = 'äöüäöü';
+        $this->assertEquals($expected, $this->_filter->filter($input));
+
+        $input    = 'äöü<!-- a comment -->äöü';
+        $input    = iconv("UTF-8", "ISO-8859-1", $input);
+        $output   = $this->_filter->filter($input);
+        $this->assertFalse(empty($output));
+    }
 }
 
 // Call Zend_Filter_StripTagsTest::main() if this source file is executed directly.