strong-soap icon indicating copy to clipboard operation
strong-soap copied to clipboard

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

Open jamienich opened this issue 1 year ago • 2 comments

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

jamienich avatar Oct 27 '24 10:10 jamienich

undefined and null semantics strike again! :-)

I think your proposal makes sense, I'd be happy to review and merge your PR for 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?

Could we add an entry to options, maybe name it attributesIgnoreUndefined (though open to suggestions).

achrinza avatar Oct 28 '24 03:10 achrinza

thanks @achrinza I've done a PR feat: wsdl option ignoreAttributesUndefined#904 first time, hopefully that looks okay. Modified the option slightly to ignoreAttributesUndefined to align with another option named ignore first.

jamienich avatar Nov 11 '24 02:11 jamienich