Skip to content

Unable to set empty XML field i.e. <somefield/> without a value or without xsi:null=true #892

Open
@jamienich

Description

@jamienich

Description/Steps to reproduce

The xmlHandler equality operator "==" evaluates undefined and null values as true as follows:

xmlHandler.js, Lines 165-173


      if (val == null) {
        if (descriptor.isNillable) {
          // Set xsi:nil = true
          declareNamespace(nsContext, element, 'xsi', helper.namespaces.xsi);
          if (typeof element.attribute === 'function') {
            element.attribute('xsi:nil', true);
          }
        }
      }

It would be preferable to set the xsi:nil = true only for null values and not undefined values.
If we exclude undefined values from the block above undefined values are shown in the XML as follows:

<some_attribute/>

Suggest using the type safe equality operator so it only evaluates null as true:


      if (val === null) { 
        if (descriptor.isNillable) { 
          // Set xsi:nil = true
          declareNamespace(nsContext, element, 'xsi', helper.namespaces.xsi);
          if (typeof element.attribute === 'function') {
            element.attribute('xsi:nil', true);
          }
        }
      }

The new code still allows strong-soap to set a xsi:nil=true when null value is passed, for undefined values however it will not do this.
Seems like a fairly major impact if users are used to xsi:null=true being set if they pass through undefined currently, thoughts on this?

Link to reproduction sandbox

Expected result

Additional information

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions