Serialize RegExp to string in JSON. Closes #119.

This commit is contained in:
Elliott Sprehn 2010-11-03 10:13:03 -07:00 committed by Igor Minar
parent 91c835dc0e
commit 690dfe000b
2 changed files with 7 additions and 0 deletions

View file

@ -33,6 +33,8 @@ function toJsonArray(buf, obj, pretty, stack){
var type = typeof obj;
if (obj === _null) {
buf.push($null);
} else if (obj instanceof RegExp) {
buf.push(angular['String']['quoteUnicode'](obj.toString()));
} else if (type === $function) {
return;
} else if (type === $boolean) {

View file

@ -30,6 +30,11 @@ describe('json', function(){
assertEquals('[1,"b"]', toJson([1,"b"]));
});
it('should parse RegExp', function() {
assertEquals('"/foo/"', toJson(/foo/));
assertEquals('[1,"/foo/"]', toJson([1,new RegExp("foo")]));
});
it('should parse IgnoreFunctions', function() {
assertEquals('[null,1]', toJson([function(){},1]));
assertEquals('{}', toJson({a:function(){}}));