comdata / x2js

Automatically exported from code.google.com/p/x2js
0 stars 0 forks source link

asArray(undefined) == [undefined] #24

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
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 commented 9 years ago
Fair [enough]. I'll fix it :)

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

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
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 commented 9 years ago
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