Skip to content

Commit

Permalink
(#4) coerse numbers to Strings for the custom filter
Browse files Browse the repository at this point in the history
  • Loading branch information
davidcalhoun committed Jun 9, 2013
1 parent 2c3c780 commit 20e99ad
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion jstoxml.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var toXML = function(obj, config){
if(!mappings.hasOwnProperty(map)) continue;
replacements.push(map);
}
return txt.replace(new RegExp('(' + replacements.join('|') + ')', 'g'), function(str, entity) {
return String(txt).replace(new RegExp('(' + replacements.join('|') + ')', 'g'), function(str, entity) {
return mappings[entity] || '';
});
};
Expand Down
10 changes: 10 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,16 @@ var jstoxml = require('./jstoxml.js');
},
expectedOutput: '<foo>true</foo><bar></bar><foo2>false</foo2><ok>This is ok</ok><ok2>false</ok2><ok3>true</ok3>'
});

addTest({
name: 'bug4',
input: function(){
return jstoxml.toXML({
foo: 4
});
},
expectedOutput: '<foo>true</foo><bar></bar><foo2>false</foo2><ok>This is ok</ok><ok2>false</ok2><ok3>true</ok3>'
});

runTests();
showReport();
Expand Down

0 comments on commit 20e99ad

Please sign in to comment.