mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-17 07:40:22 +00:00
Serialize RegExp to string in JSON. Closes #119.
This commit is contained in:
parent
91c835dc0e
commit
690dfe000b
2 changed files with 7 additions and 0 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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(){}}));
|
||||
|
|
|
|||
Loading…
Reference in a new issue