diff options
| -rw-r--r-- | src/JSON.js | 2 | ||||
| -rw-r--r-- | test/JsonSpec.js | 5 |
2 files changed, 7 insertions, 0 deletions
diff --git a/src/JSON.js b/src/JSON.js index 8606319a..b2647104 100644 --- a/src/JSON.js +++ b/src/JSON.js @@ -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) { diff --git a/test/JsonSpec.js b/test/JsonSpec.js index 17bb97b6..052c239c 100644 --- a/test/JsonSpec.js +++ b/test/JsonSpec.js @@ -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(){}})); |
