diff options
author | Shaun Verch <shaun.verch@10gen.com> | 2013-12-20 01:50:53 -0500 |
---|---|---|
committer | Shaun Verch <shaun.verch@10gen.com> | 2013-12-20 13:45:24 -0500 |
commit | 82e1fdc81552c4c1da18a129287ac4eef03d9310 (patch) | |
tree | 41fc1e06719d30a6b0d5b22a508820b7b5f20762 /src/mongo/dbtests/jsontests.cpp | |
parent | b007da8af5f9af988f8debd41e35e054e0df8732 (diff) | |
download | mongo-82e1fdc81552c4c1da18a129287ac4eef03d9310.tar.gz |
SERVER-11015 Properly quote and escape javascript code in JSON output
Diffstat (limited to 'src/mongo/dbtests/jsontests.cpp')
-rw-r--r-- | src/mongo/dbtests/jsontests.cpp | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/src/mongo/dbtests/jsontests.cpp b/src/mongo/dbtests/jsontests.cpp index a1d9f077c43..d15d2a32c91 100644 --- a/src/mongo/dbtests/jsontests.cpp +++ b/src/mongo/dbtests/jsontests.cpp @@ -454,9 +454,25 @@ namespace JsonTests { public: void run() { BSONObjBuilder b; - b.appendCode( "x" , "function(){ return 1; }" ); + b.appendCode( "x" , "function(arg){ var string = \"\\n\"; return 1; }" ); BSONObj o = b.obj(); - ASSERT_EQUALS( "{ \"x\" : function(){ return 1; } }" , o.jsonString() ); + ASSERT_EQUALS( "{ \"x\" : \"function(arg){ var string = \\\"\\\\n\\\"; " + "return 1; }\" }" , o.jsonString() ); + } + }; + + class CodeWScopeTests { + public: + void run() { + BSONObjBuilder b; + b.appendCodeWScope( "x" , "function(arg){ var string = \"\\n\"; return x; }" , + BSON("x" << 1 ) ); + BSONObj o = b.obj(); + ASSERT_EQUALS( "{ \"x\" : " + "{ \"$code\" : " + "\"function(arg){ var string = \\\"\\\\n\\\"; return x; }\" , " + "\"$scope\" : { \"x\" : 1 } } }" , + o.jsonString() ); } }; @@ -2594,6 +2610,7 @@ namespace JsonTests { add< JsonStringTests::RegexEscape >(); add< JsonStringTests::RegexManyOptions >(); add< JsonStringTests::CodeTests >(); + add< JsonStringTests::CodeWScopeTests >(); add< JsonStringTests::TimestampTests >(); add< JsonStringTests::NullString >(); add< JsonStringTests::AllTypes >(); |