Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jamienich opened this issue Oct 27, 2024 · 2 comments

Comments

@jamienich
Copy link

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

@achrinza
Copy link
Member

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).

@jamienich
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants