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

asArray(undefined) == [undefined] #24

Closed
GoogleCodeExporter opened this issue Apr 30, 2015 · 4 comments
Closed

asArray(undefined) == [undefined] #24

GoogleCodeExporter opened this issue Apr 30, 2015 · 4 comments

Comments

@GoogleCodeExporter
Copy link

Imagine you have an xml file in which an element is repeated zero or more 
times. You could have these three files following that scheme:

File 1:

<a></a>

File 2:

<a><b>1</b></a>

File 3:

<a><b>1</b><b>2</b></a>

Now, if I convert this xml to the object "obj", obj.a.b can either be 
undefined, a string or an array of strings. x2js.asArray(obj.a.b) will always 
be an array. However, for files 2 and 3 it will be an array of strings, while 
for file 1 it will be [undefined], while what I (clearly) wanted was an empty 
array (of strings).

Returning an empty array should be simple in this case and will help prevent 
errors when it turns out the element you are looking for is repeated zero times.

Original issue reported on code.google.com by jasperh...@gmail.com on 27 Jun 2014 at 11:26

@GoogleCodeExporter
Copy link
Author

Fair [enough]. I'll fix it :)

Original comment by abdulla....@gmail.com on 27 Jun 2014 at 1:08

  • Changed state: Accepted

@GoogleCodeExporter
Copy link
Author

[deleted comment]

@GoogleCodeExporter
Copy link
Author

I don't know if this covers everything, but it seems to be the only change 
necessary.

Original comment by jasperh...@gmail.com on 8 Jul 2014 at 3:20

Attachments:

@GoogleCodeExporter
Copy link
Author

Fixed, 35896f8b937c
v1.1.6 (Available in Mercurial)
Thanks for the report!

Original comment by abdulla....@gmail.com on 9 Jul 2014 at 3:27

  • Changed state: Fixed

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

No branches or pull requests

1 participant