Kaynağa Gözat

ZF-8715: consistent usage of encoding across view helpers; added note to affected view helpers

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@20143 44c647ce-9c0f-0410-b52a-842ac1e357ba
matthew 16 yıl önce
ebeveyn
işleme
5f87bfb3f0

+ 22 - 0
documentation/manual/en/module_specs/Zend_Dojo-View-Dojo.xml

@@ -110,6 +110,28 @@ $this->dojo()->enable()
         </para>
     </example>
 
+    <note>
+        <title>UTF-8 encoding used by default</title>
+
+        <para>
+            By default, Zend Framework uses <acronym>UTF-8</acronym> as its default encoding, and,
+            specific to this case, <classname>Zend_View</classname> does as well. Character encoding
+            can be set differently on the view object itself using the
+            <methodname>setEncoding()</methodname> method (or the the <varname>encoding</varname>
+            instantiation parameter). However, since <classname>Zend_View_Interface</classname> does
+            not define accessors for encoding, it's possible that if you are using a custom view
+            implementation with the Dojo view helper, you will not have a
+            <methodname>getEncoding()</methodname> method, which is what the view helper uses
+            internally for determining the character set in which to encode.
+        </para>
+
+        <para>
+            If you do not want to utilize <acronym>UTF-8</acronym> in such a situation, you will
+            need to implement a <methodname>getEncoding()</methodname> method in your custom view
+            implementation.
+        </para>
+    </note>
+
     <sect3 id="zend.dojo.view.dojo.declarative">
         <title>Programmatic and Declarative Usage of Dojo</title>
 

+ 22 - 0
documentation/manual/en/module_specs/Zend_View-Helpers-HeadStyle.xml

@@ -106,6 +106,28 @@ $this->headStyle()->appendStyle($styles, array('conditional' => 'lt IE 7'));
             helper</link>.
     </para>
 
+    <note>
+        <title>UTF-8 encoding used by default</title>
+
+        <para>
+            By default, Zend Framework uses <acronym>UTF-8</acronym> as its default encoding, and,
+            specific to this case, <classname>Zend_View</classname> does as well. Character encoding
+            can be set differently on the view object itself using the
+            <methodname>setEncoding()</methodname> method (or the the <varname>encoding</varname>
+            instantiation parameter). However, since <classname>Zend_View_Interface</classname> does
+            not define accessors for encoding, it's possible that if you are using a custom view
+            implementation with this view helper, you will not have a
+            <methodname>getEncoding()</methodname> method, which is what the view helper uses
+            internally for determining the character set in which to encode.
+        </para>
+
+        <para>
+            If you do not want to utilize <acronym>UTF-8</acronym> in such a situation, you will
+            need to implement a <methodname>getEncoding()</methodname> method in your custom view
+            implementation.
+        </para>
+    </note>
+
     <example id="zend.view.helpers.initial.headstyle.basicusage">
         <title>HeadStyle Helper Basic Usage</title>
 

+ 22 - 0
documentation/manual/en/module_specs/Zend_View-Helpers-Navigation.xml

@@ -2163,6 +2163,28 @@ echo $this->navigation()
 ]]></programlisting>
         </example>
 
+        <note>
+            <title>UTF-8 encoding used by default</title>
+
+            <para>
+                By default, Zend Framework uses <acronym>UTF-8</acronym> as its default encoding,
+                and, specific to this case, <classname>Zend_View</classname> does as well. Character
+                encoding can be set differently on the view object itself using the
+                <methodname>setEncoding()</methodname> method (or the the
+                <varname>encoding</varname> instantiation parameter). However, since
+                <classname>Zend_View_Interface</classname> does not define accessors for encoding,
+                it's possible that if you are using a custom view implementation with the Dojo view
+                helper, you will not have a <methodname>getEncoding()</methodname> method, which is
+                what the view helper uses internally for determining the character set in which to
+                encode.
+            </para>
+
+            <para>
+                If you do not want to utilize <acronym>UTF-8</acronym> in such a situation, you will
+                need to implement a <methodname>getEncoding()</methodname> method in your custom
+                view implementation.
+            </para>
+        </note>
     </sect4>
 
     <sect4 id="zend.view.helpers.initial.navigation.navigation">

+ 3 - 1
library/Zend/Dojo/View/Helper/Dojo/Container.php

@@ -1090,7 +1090,9 @@ EOJ;
         }
 
         $enc = 'UTF-8';
-        if ($this->view instanceof Zend_View_Abstract) {
+        if ($this->view instanceof Zend_View_Interface
+            && method_exists($this->view, 'getEncoding')
+        ) {
             $enc = $this->view->getEncoding();
         }
 

+ 6 - 3
library/Zend/View/Helper/Placeholder/Container/Standalone.php

@@ -122,11 +122,14 @@ abstract class Zend_View_Helper_Placeholder_Container_Standalone extends Zend_Vi
      */
     protected function _escape($string)
     {
-        if ($this->view instanceof Zend_View_Interface) {
-            return $this->view->escape($string);
+        $enc = 'UTF-8';
+        if ($this->view instanceof Zend_View_Interface
+            && method_exists($this->view, 'getEncoding')
+        ) {
+            $enc = $this->view->getEncoding();
         }
 
-        return htmlentities((string) $string, null, 'UTF-8');
+        return htmlspecialchars((string) $string, ENT_COMPAT, $enc);
     }
 
     /**