Permalink
Browse files

() fix for "0 value parsed as null".

  • Loading branch information...
1 parent fa991c3 commit 39923130aa33aa5075594a5b8c346c6dffa4b378 @zpoley committed Apr 20, 2011
Showing with 10 additions and 2 deletions.
  1. +1 −1 lib/jsonCommand.js
  2. +9 −1 test/test.js
View
@@ -171,7 +171,7 @@ JSON.Command.prototype.processArgs = function processArgs(args) {
JSON.Command.prototype.createRequestedKeys = function(parsedObject) {
// instantiate any requested keys
for(var j = 0; (j < this.keys.length); j++) {
- if (!parsedObject[this.keys[j]]) {
+ if (typeof(parsedObject[this.keys[j]]) === 'undefined') {
parsedObject[this.keys[j]] = null;
}
}
View
@@ -17,7 +17,8 @@ var testObj = {
'd', 'e', 'f'
]
},
- created_at : 127817599
+ created_at : 127817599,
+ zero : 0
};
function printTestName(testName) {
@@ -49,6 +50,13 @@ function printTestName(testName) {
assert.equal(testObj.newKey, null,
"createRequestedKeys adds requested key to object");
+
+ jsonC = new JSON.Command();
+ jsonC.processArgs([ "zero" ]);
+ jsonC.createRequestedKeys(testObj);
+
+ assert.equal(testObj.zero, 0,
+ "createRequestedKeys does not add null for 0 to object");
})();
(function testCheckConditionals() {

0 comments on commit 3992313

Please sign in to comment.