[ 
http://jira.codehaus.org/browse/DISPL-387?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_106313
 ] 

Manuel Dominguez Sarmiento commented on DISPL-387:
--------------------------------------------------

escapeHtml is not really the solution, since this will be used on XML exports 
as well, and escapeHtml also escapes ALL KNOWN HTML entities, which are quite a 
few, and are invalid in XML.

The solution is to use the following code, which works for both markup 
languages, and is in fact the approach used by the standard Apache JSTL 
implementation:

<pre>
/**
 * Safely escapes XML reserved characters for use both within XML and HTML
 * contexts.
 * 
 */
public class SafeXmlEscaper {

        /**
         * Safely escapes XML reserved characters from the input string.
         * 
         * @param s
         *            the input string.
         * @return the escaped string.
         */
        public static String escapeXml(String s) {
                StringBuilder sb = new StringBuilder();
                for (char c : s.toCharArray()) {
                        switch (c) {
                        case '&':
                                sb.append("&amp;");
                                break;
                        case '<':
                                sb.append("&lt;");
                                break;
                        case '>':
                                sb.append("&gt;");
                                break;
                        case '"':
                                sb.append("&#034;");
                                break;
                        case '\'':
                                sb.append("&#039;");
                                break;
                        default:
                                sb.append(c);
                                break;
                        }
                }
                return sb.toString();
        }
}
</pre>

> problem for  single quote escaping for single quote character in displaytag 
> column tags using escapeXML="true"
> --------------------------------------------------------------------------------------------------------------
>
>                 Key: DISPL-387
>                 URL: http://jira.codehaus.org/browse/DISPL-387
>             Project: DisplayTag
>          Issue Type: Bug
>            Reporter: ruth shacter
>
> It appears that displaytag escapes (when escapeXml="true") a single quote 
> with &apos;
> c:out and bean:write tags escape it with &#39;
> The problem is that while Firefox and Safari understand &apos;, Internet 
> Explorer does not. All three browsers understand &#39;. 
> This means that all single quotes in displaytag tables will appear as ugly 
> "&apos;". 
> This might be related to issue: maven-83:   xdocs entity encoding problem for 
> single quote
> If there is a known workaround, could you let me know? thanks.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
displaytag-devel mailing list
displaytag-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/displaytag-devel

Reply via email to