Uploaded image for project: 'VYSPER'
  1. VYSPER
  2. VYSPER-338

XMLParser.unescape throw exception

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 0.7
    • None
    • core protocol
    • None
    • java1.6, windows7

    Description

      If message stanza contains text: "辽宁" (escape before send:"辽宁")
      exception will be throw out:

      Caused by: org.xml.sax.SAXParseException: For input string: "8FBD;&#x5B81"
      at org.apache.vysper.xml.sax.impl.XMLParser.fatalError(XMLParser.java:499)
      at org.apache.vysper.xml.sax.impl.XMLParser.parse(XMLParser.java:124)
      at org.apache.vysper.xml.sax.impl.DefaultNonBlockingXMLReader.parse(DefaultNonBlockingXMLReader.java:185)
      at org.apache.vysper.xml.decoder.XMPPDecoder.doDecode(XMPPDecoder.java:117)

      Caused by:String org.apache.vysper.xml.sax.impl.XMLParser.unescape(String s)

      private String unescape(String s) {
      s = s.replace("&", "&").replace(">", ">").replace("<", "<").replace("'", "'").replace(""",
      "\"");

      StringBuffer sb = new StringBuffer();

      Matcher matcher = UNESCAPE_UNICODE_PATTERN.matcher(s);
      int end = 0;
      while (matcher.find())

      { boolean isHex = matcher.group(1).equals("x"); String unicodeCode = matcher.group(2); int base = isHex ? 16 : 10; int i = Integer.valueOf(unicodeCode, base).intValue(); char[] c = Character.toChars(i); sb.append(s.substring(end, matcher.start())); end = matcher.end(); sb.append(c); }

      sb.append(s.substring(end, s.length()));

      return sb.toString();
      }

      Replace xml predefined entities before unescape change the context of escaped strings.
      For example:
      Input: "&#x8FBD;&#x5B81;"
      After replace: "辽宁"

      unescape use regex: Pattern.compile("\\&
      #(x?)(.+);");
      match:
      group(1) = x
      group(2) = 8FBD;&#x5B81

      then Integer.valueOf(unicodeCode, base) will throw exception.
      I fixed this bug, see the patch.

      Attachments

        1. XMLParser.patch
          3 kB
          Zhang JinYan

        Activity

          People

            Unassigned Unassigned
            yearn20m Zhang JinYan
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: