9 describe('JSON', function(){
11 it('should encode and decode an object', function(){
14 s: "It's-me-Valerio!",
30 expect(JSON.decode(JSON.encode(object))).to.deep.equal(object);
34 describe('JSON', function(){
36 var win = (typeof window === 'undefined' ? global : window);
37 var goodString = '{"name":"Jim Cowart","location":{"city":{"name":"Chattanooga","population":167674}}}';
38 var badString = 'alert("I\'m a bad string!")';
40 it('should parse a valid JSON string by default', function(){
41 expect(typeOf(JSON.decode(goodString))).to.equal("object");
44 it('should parse a valid JSON string when secure is set to false', function(){
45 expect(typeOf(JSON.decode(goodString, false))).to.equal("object");
48 it('should parse a hazarous string when secure is set to false', function(){
49 var _old_alert = win.alert;
50 win.alert = function (string) {
51 if (string == "I'm a bad string!") return true;
54 expect(JSON.decode(badString, false)).to.equal(true);
55 win.alert = _old_alert;
57 it('should parse a hazarous string when JSON.secure is set to false and secure is not defined', function(){
58 var _old_alert = win.alert;
59 win.alert = function (string) {
60 if (string == "I'm a bad string!") return true;
64 expect(JSON.decode(badString)).to.equal(true);
65 win.alert = _old_alert;
68 it('should NOT parse a hazarous string by default', function(){
71 JSON.decode(badString);
75 expect(err).to.equal(true);