loopbackio / loopbackio/strong-soap

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

Open
#892 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
410
Forks
162
Avg merge
4h 36m
Merged PRs (30d)
7

Description

# 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:

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in xmlHandler.js around lines 165-173 and trace how undefined and null values are serialized. Verify that null still produces xsi:nil=true while undefined produces a self-closing element such as ; completion is confirmed when the two cases no longer share the same behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
api
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.