JSUtil: Return result quicker for isValidJSON and add additional tests.
This commit is contained in:
parent
c20a0eabed
commit
a1ee393dce
@ -32,13 +32,12 @@ module.exports = {
|
||||
try {
|
||||
parsed = JSON.parse(arg);
|
||||
} catch (e) {
|
||||
parsed = false;
|
||||
return false;
|
||||
}
|
||||
if (typeof(parsed) === 'object') {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
isHexa: isHexa,
|
||||
isHexaString: isHexa,
|
||||
|
||||
@ -13,6 +13,7 @@ describe('js utils', function() {
|
||||
|
||||
var hexa = '8080808080808080808080808080808080808080808080808080808080808080';
|
||||
var json = '{"key": ["value", "value2"]}';
|
||||
var json2 = '["value", "value2", {"key": "value"}]';
|
||||
|
||||
it('does not mistake an integer as valid json object', function() {
|
||||
var valid = JSUtil.isValidJSON(hexa);
|
||||
@ -24,6 +25,11 @@ describe('js utils', function() {
|
||||
valid.should.equal(true);
|
||||
});
|
||||
|
||||
it('correctly validates an array json object', function() {
|
||||
var valid = JSUtil.isValidJSON(json);
|
||||
valid.should.equal(true);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user