Преглед изворни кода

ZF-11617
Zend_Filter
Allow hyphenated attribute names in Zend_Filter_StripTags


git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@24277 44c647ce-9c0f-0410-b52a-842ac1e357ba

adamlundrigan пре 14 година
родитељ
комит
1253d7c4b2
2 измењених фајлова са 15 додато и 1 уклоњено
  1. 1 1
      library/Zend/Filter/StripTags.php
  2. 14 0
      tests/Zend/Filter/StripTagsTest.php

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

@@ -319,7 +319,7 @@ class Zend_Filter_StripTags implements Zend_Filter_Interface
         // If there are non-whitespace characters in the attribute string
         // If there are non-whitespace characters in the attribute string
         if (strlen($tagAttributes)) {
         if (strlen($tagAttributes)) {
             // Parse iteratively for well-formed attributes
             // Parse iteratively for well-formed attributes
-            preg_match_all('/(\w+)\s*=\s*(?:(")(.*?)"|(\')(.*?)\')/s', $tagAttributes, $matches);
+            preg_match_all('/([\w-]+)\s*=\s*(?:(")(.*?)"|(\')(.*?)\')/s', $tagAttributes, $matches);
 
 
             // Initialize valid attribute accumulator
             // Initialize valid attribute accumulator
             $tagAttributes = '';
             $tagAttributes = '';

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

@@ -606,6 +606,20 @@ class Zend_Filter_StripTagsTest extends PHPUnit_Framework_TestCase
         $expected = 'text';
         $expected = 'text';
         $this->assertEquals($expected, $this->_filter->filter($input));
         $this->assertEquals($expected, $this->_filter->filter($input));
     }
     }
+    
+    /**
+     * @group ZF-11617
+     */
+    public function testFilterCanAllowHyphenatedAttributeNames()
+    {
+        $input     = '<li data-disallowed="no!" data-name="Test User" data-id="11223"></li>';
+        $expected  = '<li data-name="Test User" data-id="11223"></li>';
+        
+        $this->_filter->setTagsAllowed('li');
+        $this->_filter->setAttributesAllowed(array('data-id','data-name'));
+        
+        $this->assertEquals($expected, $this->_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.