Skip to content

Commit 6e6ada9

Browse files
committed
Revert r28, commit was incomplete
1 parent 50f8157 commit 6e6ada9

File tree

3 files changed

+8
-59
lines changed

3 files changed

+8
-59
lines changed

src/jquery.json.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
return undefined;
5353
}
5454
if ( type === 'number' || type === 'boolean' ) {
55-
return '' + o;
55+
return o + '';
5656
}
5757
if ( type === 'string') {
5858
return $.quoteString( o );
@@ -96,17 +96,16 @@
9696
'.' + milli + 'Z"';
9797
}
9898
if ( o.constructor === Array ) {
99-
var ret = [], i = 0;
100-
for ( ; i < o.length; i++ ) {
99+
var ret = [];
100+
for ( var i = 0; i < o.length; i++ ) {
101101
ret.push( $.toJSON( o[i] ) || 'null' );
102102
}
103103
return '[' + ret.join(',') + ']';
104104
}
105105
var name,
106106
val,
107-
k,
108107
pairs = [];
109-
for ( k in o ) {
108+
for ( var k in o ) {
110109
type = typeof k;
111110
if ( type === 'number' ) {
112111
name = '"' + k + '"';
@@ -155,7 +154,7 @@
155154
return JSON.parse( src );
156155
}
157156

158-
var filtered =
157+
var filtered =
159158
src
160159
.replace( /\\["\\\/bfnrtu]/g, '@' )
161160
.replace( /"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']')

src/jquery.json.min.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
(function($){var escapeable=/["\\\x00-\x1f\x7f-\x9f]/g,meta={'\b':'\\b','\t':'\\t','\n':'\\n','\f':'\\f','\r':'\\r','"':'\\"','\\':'\\\\'};$.toJSON=function(o){if(typeof JSON==='object'&&JSON.stringify){return JSON.stringify(o);}
33
var type=typeof o;if(o===null){return'null';}
44
if(type==='undefined'){return undefined;}
5-
if(type==='number'||type==='boolean'){return''+o;}
5+
if(type==='number'||type==='boolean'){return o+'';}
66
if(type==='string'){return $.quoteString(o);}
77
if(type==='object'){if(typeof o.toJSON==='function'){return $.toJSON(o.toJSON());}
88
if(o.constructor===Date){var month=o.getUTCMonth()+1,day=o.getUTCDate(),year=o.getUTCFullYear(),hours=o.getUTCHours(),minutes=o.getUTCMinutes(),seconds=o.getUTCSeconds(),milli=o.getUTCMilliseconds();if(month<10){month='0'+month;}
@@ -14,9 +14,9 @@ if(milli<100){milli='0'+milli;}
1414
if(milli<10){milli='0'+milli;}
1515
return'"'+year+'-'+month+'-'+day+'T'+
1616
hours+':'+minutes+':'+seconds+'.'+milli+'Z"';}
17-
if(o.constructor===Array){var ret=[],i=0;for(;i<o.length;i++){ret.push($.toJSON(o[i])||'null');}
17+
if(o.constructor===Array){var ret=[];for(var i=0;i<o.length;i++){ret.push($.toJSON(o[i])||'null');}
1818
return'['+ret.join(',')+']';}
19-
var name,val,k,pairs=[];for(k in o){type=typeof k;if(type==='number'){name='"'+k+'"';}else if(type==='string'){name=$.quoteString(k);}else{continue;}
19+
var name,val,pairs=[];for(var k in o){type=typeof k;if(type==='number'){name='"'+k+'"';}else if(type==='string'){name=$.quoteString(k);}else{continue;}
2020
type=typeof o[k];if(type==='function'||type==='undefined'){continue;}
2121
val=$.toJSON(o[k]);pairs.push(name+':'+val);}
2222
return'{'+pairs.join(',')+'}';}};$.evalJSON=function(src){if(typeof JSON==='object'&&JSON.parse){return JSON.parse(src);}

test/jquery.json.test.js

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -173,53 +173,3 @@ test( 'Undefined and null', function(){
173173

174174

175175
});
176-
177-
178-
// Utility function
179-
function testEvalJSON( string, json, description ) {
180-
// deepEqual traverses an object's members,
181-
// this is needed because a simple == comparison doesn't
182-
// work because objects are comparsed by reference, not by value.
183-
// For example [1,2,3] == [1,2,3] returns false :)
184-
deepEqual( $.evalJSON( string ), json, description );
185-
}
186-
187-
module( 'jQuery.evalJSON' );
188-
189-
test( 'Basic', function(){
190-
191-
testEvalJSON(
192-
'"hi"',
193-
"hi",
194-
'Simple string'
195-
);
196-
testEvalJSON(
197-
'{"apple":2}',
198-
{"apple":2},
199-
'Object'
200-
);
201-
testEvalJSON(
202-
'{"apple":{"apple":2}}',
203-
{"apple":{"apple":2}},
204-
'Objects inside objects'
205-
);
206-
testEvalJSON(
207-
'{"apple":7,"pear":5}',
208-
{"apple":7,"pear":5},
209-
'Objects with multiple members'
210-
);
211-
212-
});
213-
214-
test( 'Invalid input', function(){
215-
216-
raises(
217-
function(){
218-
$.evalJSON( '{ "foo": \'100\' }' );
219-
},
220-
SyntaxError,
221-
'Single quotes are invalid, the should throw a syntax error.'
222-
);
223-
224-
225-
});

0 commit comments

Comments
 (0)