Uploaded image for project: 'XMLBeans'
  1. XMLBeans
  2. XMLBEANS-599

Line breaks in base64binary cause a validation error

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • Version 5.0.3
    • Version 5.1.0
    • None
    • None

    Description

      When trying to migrate from XmlBeans 3.1.0 to 5.0.3 the following issue caused some unit tests to fail:
       
      The XML data contains elements of type base64binary which have line breaks.
      Validation via XmlObject.validate() now returns an error:
      "error: base64Binary: Invalid value: not encoded properly".

      The error originates from the class org.apache.xmlbeans.impl.values.JavaBase64Holder:

          public static byte[] lex(String v, ValidationContext c) {
              try {
                  return Base64.getDecoder().decode(v);
              } catch (IllegalArgumentException var3) {
                  c.invalid("base64Binary", new Object[]{"not encoded properly"});
                  return null;
              }
          }
      

      The decode call fails with an IllegalArgumentException "Illegal base64 character 20".
      (It's character 20 because XmlBeans converts the line break to a space in XmlWhitespace.collapse().)

      The definition of the base64binary type allows for the presence of whitespace
      https://www.w3.org/TR/xmlschema-2/#base64Binary

      Therefore I'd suggest to change the Base64 call as follows:

      Base64.getMimeDecoder().decode(v);
      

      Attachments

        Activity

          People

            pj.fanning PJ Fanning
            dhengst Daniel Hengst
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 10m
                10m