Ver código fonte

[ZF-9828] Zend_Filter:

- fixed single quoted attributes

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@22173 44c647ce-9c0f-0410-b52a-842ac1e357ba
thomas 15 anos atrás
pai
commit
de2f86a017

+ 3 - 3
library/Zend/Filter/StripTags.php

@@ -1,5 +1,4 @@
 <?php
 <?php
-
 /**
 /**
  * Zend Framework
  * Zend Framework
  *
  *
@@ -254,6 +253,7 @@ class Zend_Filter_StripTags implements Zend_Filter_Interface
         // Parse the input data iteratively as regular pre-tag text followed by a
         // Parse the input data iteratively as regular pre-tag text followed by a
         // tag; either may be empty strings
         // tag; either may be empty strings
         preg_match_all('/([^<]*)(<?[^>]*>?)/', (string) $value, $matches);
         preg_match_all('/([^<]*)(<?[^>]*>?)/', (string) $value, $matches);
+
         // Iterate over each set of matches
         // Iterate over each set of matches
         foreach ($matches[1] as $index => $preTag) {
         foreach ($matches[1] as $index => $preTag) {
             // If the pre-tag text is non-empty, strip any ">" characters from it
             // If the pre-tag text is non-empty, strip any ">" characters from it
@@ -320,8 +320,8 @@ class Zend_Filter_StripTags implements Zend_Filter_Interface
             // Iterate over each matched attribute
             // Iterate over each matched attribute
             foreach ($matches[1] as $index => $attributeName) {
             foreach ($matches[1] as $index => $attributeName) {
                 $attributeName      = strtolower($attributeName);
                 $attributeName      = strtolower($attributeName);
-                $attributeDelimiter = $matches[2][$index];
-                $attributeValue     = $matches[3][$index];
+                $attributeDelimiter = empty($matches[2][$index]) ? $matches[4][$index] : $matches[2][$index];
+                $attributeValue     = empty($matches[3][$index]) ? $matches[5][$index] : $matches[3][$index];
 
 
                 // If the attribute is not allowed, then remove it entirely
                 // If the attribute is not allowed, then remove it entirely
                 if (!array_key_exists($attributeName, $this->_tagsAllowed[$tagName])
                 if (!array_key_exists($attributeName, $this->_tagsAllowed[$tagName])

+ 17 - 0
tests/Zend/Filter/StripTagsTest.php

@@ -585,6 +585,23 @@ class Zend_Filter_StripTagsTest extends PHPUnit_Framework_TestCase
         $expected = 'test <a /> test div-content';
         $expected = 'test <a /> test div-content';
         $this->assertEquals($expected, $filter->filter($input));
         $this->assertEquals($expected, $filter->filter($input));
     }
     }
+
+    /**
+     * @group ZF-9828
+     */
+    public function testMultiQuoteInput()
+    {
+        $filter = new Zend_Filter_StripTags(
+            array(
+                'allowTags' => 'img',
+                'allowAttribs' => array('width', 'height', 'src')
+            )
+        );
+
+        $input    = '<img width="10" height="10" src=\'wont_be_matched.jpg\'>';
+        $expected = '<img width="10" height="10" src=\'wont_be_matched.jpg\'>';
+        $this->assertEquals($expected, $filter->filter($input));
+    }
 }
 }
 
 
 // Call Zend_Filter_StripTagsTest::main() if this source file is executed directly.
 // Call Zend_Filter_StripTagsTest::main() if this source file is executed directly.