XStream
  1. XStream
  2. XSTR-126

Problem deserializing less than and greater than strings

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.1
    • Component/s: None
    • Labels:
      None

      Description

      From Stephen McNabb
      -----------------------

      I've started to use XStream to serialize objects that need to be persisted in a database and I've run in to what I hope is a simple problem to fix. I can't seem to get it to deserialize objects that have Strings containing less than or greater than signs. The code is running in WebLogic 7 with jdk131_08, so I'm using the PureJavaReflectionProvider provider.

      I have attaced the code for a unit test I put together to show the problem at the end of this email.

      As you can see if the String contains only a less than sign, greater than sign or a less than greater than sign, then an empty String is returned by XStream.fromXML. I have included the xml in the comments below and as you can see it seems to be encoding the less than and greater than signs. The problem seems to be when the xml is passed to the fromXML method.

      Any help or guidance you can give me would be much appreciated.

      Thanks for a great library,

      Steve

      ----------------------------------------

      import com.thoughtworks.xstream.XStream;
      import com.thoughtworks.xstream.converters.reflection.PureJavaReflectionProvider;

      import junit.framework.TestCase;

      public class XStreamTests extends TestCase {

      // Fails. newString = ""
      // xml = "<string><</string>"
      public void testLessThan() throws Exception

      { String oldString = new String("<"); String newString = encodeDecode(oldString); assertEquals(oldString, newString); }

      // Fails. newString = ""
      // xml = "<string>></string>"
      public void testGreaterThan() throws Exception

      { String oldString = new String(">"); String newString = encodeDecode(oldString); assertEquals(oldString, newString); }

      // Fails. newString = ""
      // xml = "<string><></string>"
      public void testLessThanGreaterThan() throws Exception

      { String oldString = new String("<>"); String newString = encodeDecode(oldString); assertEquals(oldString, newString); }

      // Passes
      // xml = "<string><=</string>"
      public void testLessThanEqualTo() throws Exception

      { String oldString = new String("<="); String newString = encodeDecode(oldString); assertEquals(oldString, newString); }

      // Passes
      // xml = "<string>>=</string>"
      public void testGreaterThanEqualTo() throws Exception

      { String oldString = new String(">="); String newString = encodeDecode(oldString); assertEquals(oldString, newString); }

      private String encodeDecode(String value) throws Exception

      { XStream xs = new XStream(new PureJavaReflectionProvider()); String xml = xs.toXML(value); return (String)xs.fromXML(xml); }

      }

      ----------------------------------------

        People

        • Assignee:
          Unassigned
          Reporter:
          Joe Walnes
        • Votes:
          0 Vote for this issue
          Watchers:
          1 Start watching this issue

          Dates

          • Created:
            Updated:
            Resolved: