forked from Azure/azure-sdk-for-js
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[core-http] de-serialize empty wrapped xml element list properly
When de-serializing an empty list of xml elements we expect to get an empty array `[]` back. However, currently we get the empty string `''` instead. The cause of the issue is that when de-serializing wrapped xml list, we were re-using the variable `unwrappedProperty`, and a short-circuit: ```typescript unwrappedProperty = responseBody[xmlName!]; // line.1 unwrappedProperty = unwrappedProperty && unwrappedProperty[xmlElementName!]; // line.2 ``` In a normal case of ```xml <Cors> <CorsRule>...</CorsRule> <CorsRule>...</CorsRule> </Cors> ``` The parsed object (`responseBody`) from xml parser is ```js { Cors: { CorsRule: [{...}, {...}] } } ``` After line.1, we have `unwrappedProperty` with value `{ CorsRule: [{...}, {...}] }`. Then after line.2, we have `unwrappedProperty` with the array as its value. So far so good. However, in the failing case of ```xml <Cors /> ``` The parsed object from xml parser is ```js { Cors: '' } ``` After the first line, we have `unwrappedProperty` as the empty string `''`, the short-circuit on line two keeps `unwrappedProperty` as `''`, which fails the condition ```typescript const isEmptyWrappedList = unwrappedProperty === undefined; ``` therefore, the expected empty array is not assigned. This change removes the confusing mutable variable and the short-circuit. Now we just pick the empty array if the wrapped property is falsy. Fixes Azure#11071
- Loading branch information
1 parent
db93f16
commit da579af
Showing
3 changed files
with
285 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters