ソースを参照

ZF-9532: Conditional comments in headStyle()

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@23680 44c647ce-9c0f-0410-b52a-842ac1e357ba
intiilapa 15 年 前
コミット
b5003f21a2

+ 12 - 5
library/Zend/View/Helper/HeadStyle.php

@@ -355,14 +355,21 @@ class Zend_View_Helper_HeadStyle extends Zend_View_Helper_Placeholder_Container_
             }
         }
 
+        $escapeStart = $indent . '<!--'. PHP_EOL;
+        $escapeEnd = $indent . '-->'. PHP_EOL;
+        if (isset($item->attributes['conditional'])
+            && !empty($item->attributes['conditional'])
+            && is_string($item->attributes['conditional'])
+        ) {
+            $escapeStart = null;
+            $escapeEnd = null;
+        }
+
         $html = '<style type="text/css"' . $attrString . '>' . PHP_EOL
-              . $indent . '<!--' . PHP_EOL . $indent . $item->content . PHP_EOL . $indent . '-->' . PHP_EOL
+              . $escapeStart . $indent . $item->content . PHP_EOL . $escapeEnd
               . '</style>';
 
-        if (isset($item->attributes['conditional'])
-            && !empty($item->attributes['conditional'])
-            && is_string($item->attributes['conditional']))
-        {
+        if (null == $escapeStart && null == $escapeEnd) {
             $html = '<!--[if ' . $item->attributes['conditional'] . ']> ' . $html . '<![endif]-->';
         }
 

+ 15 - 0
tests/Zend/View/Helper/HeadStyleTest.php

@@ -442,6 +442,21 @@ a {
 
         $this->assertEquals($expected, $test);
     }
+
+    /**
+     * @group ZF-9532
+     */
+    public function testRenderConditionalCommentsShouldNotContainHtmlEscaping()
+    {
+        $style = 'a{display:none;}';
+        $this->helper->appendStyle($style, array(
+        	'conditional' => 'IE 8'
+        ));
+        $value = $this->helper->toString();
+
+        $this->assertNotContains('<!--' . PHP_EOL, $value);
+        $this->assertNotContains(PHP_EOL . '-->', $value);
+    }
 }
 
 // Call Zend_View_Helper_HeadStyleTest::main() if this source file is executed directly.