You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Thomas Neidhart (JIRA)" <ji...@apache.org> on 2013/10/20 10:08:42 UTC

[jira] [Comment Edited] (LANG-898) StringEscapeUtils un/escapexml inconsistant with escaped whitespace

    [ https://issues.apache.org/jira/browse/LANG-898?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13799973#comment-13799973 ] 

Thomas Neidhart edited comment on LANG-898 at 10/20/13 8:07 AM:
----------------------------------------------------------------

Afaik, it is not mandatory to escape CR & LF in xml documents, thus it is also not done by default when calling StringEscapeUtils.escapeXml.

You can create your own translater that will also escape LF like this:

{noformat}
StringEscapeUtils.ESCAPE_XML.with(NumericEntityEscaper.between(0x0F, 0x11)).translate(...);
{noformat}


was (Author: tn):
Afaik, it is not mandatory to escape CR & LF in xml documents, thus it is also not done by default when calling StringEscapeUtils.escapeXml.

You can create your own translater that will also escape LF like this:

{noformat}
StringEscapeUtils.ESCAPE_XML.with(NumericEntityEscaper.between(0x09, 0x11)).translate(...);
{noformat}

> StringEscapeUtils un/escapexml inconsistant with escaped whitespace
> -------------------------------------------------------------------
>
>                 Key: LANG-898
>                 URL: https://issues.apache.org/jira/browse/LANG-898
>             Project: Commons Lang
>          Issue Type: Bug
>          Components: lang.*
>    Affects Versions: 3.1
>         Environment: Windows 7, Java 7
>            Reporter: Martin Barrs
>            Priority: Minor
>
> {noformat} 
> In an escaped XML string with escaped whitespace, in this case linefeed ( &#10; ), escapexml and unescapexml treat the linefeed inconsistently. 
> unescape converts &#10; to a linefeed, yet escapexml does not convert linefeed back to &#10;
> Here's code and output...
> public static void main(String[] args) {
>         String escaped =
>                 "&lt;?xml version=&quot;1.0&quot; encoding=&quot;iso-8859-1&quot;?&gt;&#10;&lt;?xml version=&quot;1.0&quot; encoding=&quot;iso-8859-1&quot;?&gt;";
>         System.out.println(escaped);
>         System.out.println();
>         System.out.println(StringEscapeUtils.unescapeXml(escaped));
>         System.out.println();
>         System.out.println(StringEscapeUtils.escapeXml(StringEscapeUtils
>                 .unescapeXml(escaped)));
>     }
>     
> Output:
> &lt;?xml version=&quot;1.0&quot; encoding=&quot;iso-8859-1&quot;?&gt;&#10;&lt;?xml version=&quot;1.0&quot; encoding=&quot;iso-8859-1&quot;?&gt;
> <?xml version="1.0" encoding="iso-8859-1"?>
> <?xml version="1.0" encoding="iso-8859-1"?>
> &lt;?xml version=&quot;1.0&quot; encoding=&quot;iso-8859-1&quot;?&gt;
> &lt;?xml version=&quot;1.0&quot; encoding=&quot;iso-8859-1&quot;?&gt;
> {noformat} 



--
This message was sent by Atlassian JIRA
(v6.1#6144)