peerlibrary / node-xml4js

XML to JavaScript parser using XML Schema to guide conversion
BSD 3-Clause "New" or "Revised" License
60 stars 11 forks source link

Fix for boolean always parsed as 'true' #6

Closed corsica closed 9 years ago

corsica commented 9 years ago

Thanks for the great library, fixed a little bug.

mitar commented 9 years ago

Please don't bump the version yourself. Also, could you make a test for this?

mitar commented 9 years ago

Just add to one of "other" tests one true and one false boolean somewhere.

corsica commented 9 years ago

I noticed that all parsings to JS of my XML files (with a Schema) using your lib returned only true for the boolean values, regardless of the boolean value in the XML was true or false.

Gladly I could quickly find it in your code and fix it. Tested it and it works. Didn't take the time to fix any tests you might have though.

Here's the change in xsd.js:

 BASE_TYPES.boolean = {
   parse: function (value) {
-    return _.contains(['true', 'false', '0', '1'], value.toLowerCase());
+    return _.contains(['true', '1'], value.toLowerCase());
   }
 };

As you can see, no matter whether (input-) value contains 'true', 'false', '0' or '1', it will return true.

Sorry for my lousy commit messages, didn't sleep that day :-)

mitar commented 9 years ago

Yea, change looks good. Thanks. Could you make this into a full pull request?

corsica commented 9 years ago

Ok, changed the test and cleaned up. The changed test fails with old code, succeeds with the change.

mitar commented 9 years ago

Perfect. Thanks.

mitar commented 9 years ago

Published.