You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by "JBert (Issue Comment Edited) (JIRA)" <ji...@apache.org> on 2011/12/12 12:38:30 UTC

[jira] [Issue Comment Edited] (COCOON3-83) Encoding bug in XMLGenerator (SAX version) when passing a String to the constructor

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

JBert edited comment on COCOON3-83 at 12/12/11 11:37 AM:
---------------------------------------------------------

The problem would appear to be in the StringGenerator inner class, in version 3.0.0-alpha 3 the problem is on line 322:
           XMLUtils.toSax(new ByteArrayInputStream(this.xmlString.getBytes()), XMLGenerator.this.getSAXConsumer());


This encodes the String to bytes using the JRE platform encoding. A SAX parser will later have trouble parsing this bytestream when the XML declares an encoding different from the platform encoding.

If I look at line 149, there's this:
               XMLUtils.toSax(new String(this.bytes, this.encoding), XMLGenerator.this.getSAXConsumer());

This issue could thus be fixed by simply passing the XML String into the toSax function, like so (line 322 again):
             XMLUtils.toSax(this.xmlString, XMLGenerator.this.getSAXConsumer());
                
      was (Author: albertdevs):
    The problem would appear to be in the StringGenerator inner class, in version 3.0.0-alpha 3 the problem is on line 322:

{code}
    XMLUtils.toSax(new ByteArrayInputStream(this.xmlString.getBytes()), XMLGenerator.this.getSAXConsumer());
{code}

This encodes the String to bytes using the JRE platform encoding. A SAX parser will later have trouble parsing this bytestream when the XML declares an encoding different from the platform encoding.

If I look at line 149, there's this:
{code}
             XMLUtils.toSax(new String(this.bytes, this.encoding), XMLGenerator.this.getSAXConsumer());
{code}

This issue could thus be fixed by simply passing the XML String into the toSax function, like so:

{code}
             XMLUtils.toSax(this.xmlString, XMLGenerator.this.getSAXConsumer());
{code}
                  
> Encoding bug in XMLGenerator (SAX version) when passing a String to the constructor
> -----------------------------------------------------------------------------------
>
>                 Key: COCOON3-83
>                 URL: https://issues.apache.org/jira/browse/COCOON3-83
>             Project: Cocoon 3
>          Issue Type: Bug
>          Components: cocoon-sax
>    Affects Versions: 3.0.0-alpha-3
>            Reporter: JBert
>
> When creating a new org.apache.cocoon.sax.component.XMLGenerator instance with a String argument, the execute method will fail when the XML uses non-ASCII characters.
> See http://stackoverflow.com/a/8471886/983949 for more info with regards to the code.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira