Apache Flex
  1. Apache Flex
  2. FLEX-33644

XMLEncoder improperly handles encoding the string "null".

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: Adobe Flex SDK 3.0 (Release), Adobe Flex SDK 3.1 (Release), Adobe Flex SDK 3.2 (Release), Adobe Flex SDK 3.3 (Release), Adobe Flex SDK 3.4 (Release), Adobe Flex SDK 3.5 (Release), Adobe Flex SDK 3.6 (Release), Apache Flex 4.9.0
    • Fix Version/s: None
    • Component/s: RPC: General
    • Labels:

      Description

      The following code returns an empty string:

      var enc:XMLEncoder = new XMLEncoder();
      enc.encode("null");

      However, SchemaMarshaller.marshall() correctly returns the string "null".

      I believe the problems is that XML.appendChild (as used in XMLEncoder.setValue) for some reason treats the string "null" differently. I have no idea why.

      If you're curious as to why I think this is a bug, see this StackOverflow question:
      http://stackoverflow.com/questions/4456438/how-can-i-pass-the-string-null-through-wsdl-soap-from-as3-to-coldfusion-web

      Finally, see this fiddle for examples:
      http://wonderfl.net/c/jYIm

        Activity

        Hide
        Ben Burns added a comment - - edited

        Thanks, Justin. I created a fork of my fiddle test case to demonstrate what you're saying. http://wonderfl.net/c/dd23/read

        Personally I think the real problem is that anything would ever coerce to null, or that null would ever coerce to <root>null</root>. It's my opinion that null should only ever be coerced to false (or maybe the opposite to prevent weird coercion chains) in languages which support type coercion, and that for all other purposes, a == null should be identical to a === null. In lieu of making that change, I'd recommend auditing all flex XML processing code for null checks using the weak equality operator where they should in fact be using the strict equality operator.

        Show
        Ben Burns added a comment - - edited Thanks, Justin. I created a fork of my fiddle test case to demonstrate what you're saying. http://wonderfl.net/c/dd23/read Personally I think the real problem is that anything would ever coerce to null, or that null would ever coerce to <root>null</root>. It's my opinion that null should only ever be coerced to false (or maybe the opposite to prevent weird coercion chains) in languages which support type coercion, and that for all other purposes, a == null should be identical to a === null. In lieu of making that change, I'd recommend auditing all flex XML processing code for null checks using the weak equality operator where they should in fact be using the strict equality operator.
        Hide
        Justin Mclean added a comment -

        This is the cause of the issue (at the bottom of the encode method there a similar condition).

        var nullXML:XML = <root>null</root>;

        if (nullXML == null)

        { trace("Some XML is null"); }

        nullXML == null is true!

        Not 100% sure what the best fix is - suggestions welcome.

        Show
        Justin Mclean added a comment - This is the cause of the issue (at the bottom of the encode method there a similar condition). var nullXML:XML = <root>null</root>; if (nullXML == null) { trace("Some XML is null"); } nullXML == null is true! Not 100% sure what the best fix is - suggestions welcome.
        Ben Burns made changes -
        Affects Version/s Adobe Flex SDK 3.3 (Release) [ 12321766 ]
        Affects Version/s Adobe Flex SDK 3.4 (Release) [ 12321767 ]
        Affects Version/s Adobe Flex SDK 3.5 (Release) [ 12321768 ]
        Affects Version/s Adobe Flex SDK 3.6 (Release) [ 12321769 ]
        Ben Burns made changes -
        Affects Version/s Apache Flex 4.9.0 [ 12322502 ]
        Affects Version/s Adobe Flex SDK 3.0 (Release) [ 12321763 ]
        Affects Version/s Adobe Flex SDK 3.1 (Release) [ 12321764 ]
        Affects Version/s Adobe Flex SDK 3.2 (Release) [ 12321765 ]
        Affects Version/s Adobe Flex SDK 3.5 (Release) [ 12321768 ]
        Hide
        Ben Burns added a comment - - edited

        Edited description to reflect my present understanding of what's going on (and perhaps to remove my prior stupidity about type coercion as it applies to the null literal).

        Show
        Ben Burns added a comment - - edited Edited description to reflect my present understanding of what's going on (and perhaps to remove my prior stupidity about type coercion as it applies to the null literal).
        Ben Burns made changes -
        Description The following code returns an empty string:

            var enc:XMLEncoder = new XMLEncoder();
            enc.encode("null");

        However, SchemaMarshaller.marshall() correctly returns the string "null".

        I believe the problems is that XML.appendChild for some reason treats the string "null" differently. I have no idea why.

        If you're curious as to why I think this is a bug, see this StackOverflow question:
        http://stackoverflow.com/questions/4456438/how-can-i-pass-the-string-null-through-wsdl-soap-from-as3-to-coldfusion-web

        Finally, see this fiddle for examples:
        http://wonderfl.net/c/jYIm
        The following code returns an empty string:

            var enc:XMLEncoder = new XMLEncoder();
            enc.encode("null");

        However, SchemaMarshaller.marshall() correctly returns the string "null".

        I believe the problems is that XML.appendChild (as used in XMLEncoder.setValue) for some reason treats the string "null" differently. I have no idea why.

        If you're curious as to why I think this is a bug, see this StackOverflow question:
        http://stackoverflow.com/questions/4456438/how-can-i-pass-the-string-null-through-wsdl-soap-from-as3-to-coldfusion-web

        Finally, see this fiddle for examples:
        http://wonderfl.net/c/jYIm
        Ben Burns made changes -
        Labels easyfix rpc soap xml xmlrpc rpc soap xml xmlrpc
        Ben Burns made changes -
        Description Found this bug while researching an answer for this StackOverflow question: http://stackoverflow.com/questions/4456438/how-can-i-pass-the-string-null-through-wsdl-soap-from-as3-to-coldfusion-web

        If XMLEncoder is passed a string "null" (that is, a proper string, not null the placeholder value), it's possible that the value will not be included in the encoded output. This appears to be because of the equality check here: https://git-wip-us.apache.org/repos/asf?p=flex-sdk.git;a=blob;f=frameworks/projects/rpc/src/mx/rpc/xml/XMLEncoder.as;h=f9a223e66e35fa8a11095e4e458c5a09d92678eb;hb=4f20635628acdc09e8739c5f94ec644d20cbd959#l101 (this is HEAD at time of posting).

        I believe that in that case, null is coerced to "null" and the equality test succeeds which in turn sets content to null, causing the output to be omitted later in the encode method.

        Note that this has been a problem since at least Flex 3.5, and probably longer. http://opensource.adobe.com/svn/opensource/flex/sdk/tags/3.5.0.12683/frameworks/projects/rpc/src/mx/rpc/xml/XMLEncoder.as
        The following code returns an empty string:

            var enc:XMLEncoder = new XMLEncoder();
            enc.encode("null");

        However, SchemaMarshaller.marshall() correctly returns the string "null".

        I believe the problems is that XML.appendChild for some reason treats the string "null" differently. I have no idea why.

        If you're curious as to why I think this is a bug, see this StackOverflow question:
        http://stackoverflow.com/questions/4456438/how-can-i-pass-the-string-null-through-wsdl-soap-from-as3-to-coldfusion-web

        Finally, see this fiddle for examples:
        http://wonderfl.net/c/jYIm
        Justin Mclean made changes -
        Field Original Value New Value
        Labels rpc soap xml xmlrpc easyfix rpc soap xml xmlrpc
        Ben Burns created issue -

          People

          • Assignee:
            Unassigned
            Reporter:
            Ben Burns
          • Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:

              Development