harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Andrew Cornwall (JIRA)" <j...@apache.org>
Subject [jira] Commented: (HARMONY-4448) XMLEncoded Strings with \n are decoded incorrectly
Date Thu, 12 Jul 2007 18:47:04 GMT

    [ https://issues.apache.org/jira/browse/HARMONY-4448?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12512210
] 

Andrew Cornwall commented on HARMONY-4448:
------------------------------------------

A possible fix for this is to change Command.setData(String) to: 

    public void setData(String data) {
    	if(this.data == null) {
    		this.data = data;
    	} else {
    		this.data = this.data + data;
    	}
    }

and Handler.characters(char[]) to:
    @Override
    public void characters(char[] text, int start, int length)
            throws SAXException {
        if (length > 0) {
            String data = String.valueOf(text, start, length)
                    /* .replace('\n', ' ').replace('\t', ' ').trim() */;
            if (data.length() > 0) {
                Command.prn(tabCount, tabCount + ">setting data=" + data //$NON-NLS-1$
                        + "<EOL>"); //$NON-NLS-1$
                Command cmd = stack.peek();
                cmd.setData(data);
            }
        }
    }

but I'm not sure if this breaks other things.


> XMLEncoded Strings with \n are decoded incorrectly
> --------------------------------------------------
>
>                 Key: HARMONY-4448
>                 URL: https://issues.apache.org/jira/browse/HARMONY-4448
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>         Environment: M2 on Win x86
>            Reporter: Andrew Cornwall
>
> XMLEncoded Strings which have a \n in them (such as "hello\nthere") are decoded
> incorrectly.
> The following testcase demonstrates the issue:
> public class Bug126404 {
>     public static void main (String args[]) {
> 	Object object = null;
> 	String encodedString = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
> 	"<java version=\"1.5.0\" class=\"java.beans.XMLDecoder\">\n" +
> 	" <string>hello\n" +
> 	"there</string>\n" +
> 	"</java>\n";
> 	byte[] in = encodedString.getBytes();
> 	ByteArrayInputStream inputStream = new ByteArrayInputStream(in);
> 	XMLDecoder decoder = new XMLDecoder(inputStream, "CDS");
> 	try{
> 	    object = decoder.readObject();
> 	}
> 	catch (Exception ex) { 
> 	    ex.printStackTrace();
> 	}
> 	System.out.println(new String(object.toString()));
>     }
> }
> On Sun JDK, this results in:
> hello
> there
> On Harmony M2, this results in:
> there

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message