mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-05-18 19:41:07 +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;
|
var type = typeof obj;
|
||||||
if (obj === _null) {
|
if (obj === _null) {
|
||||||
buf.push($null);
|
buf.push($null);
|
||||||
|
} else if (obj instanceof RegExp) {
|
||||||
|
buf.push(angular['String']['quoteUnicode'](obj.toString()));
|
||||||
} else if (type === $function) {
|
} else if (type === $function) {
|
||||||
return;
|
return;
|
||||||
} else if (type === $boolean) {
|
} else if (type === $boolean) {
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,11 @@ describe('json', function(){
|
||||||
assertEquals('[1,"b"]', toJson([1,"b"]));
|
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() {
|
it('should parse IgnoreFunctions', function() {
|
||||||
assertEquals('[null,1]', toJson([function(){},1]));
|
assertEquals('[null,1]', toJson([function(){},1]));
|
||||||
assertEquals('{}', toJson({a:function(){}}));
|
assertEquals('{}', toJson({a:function(){}}));
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue