summaryrefslogtreecommitdiff
path: root/db/jsobj.cpp
diff options
context:
space:
mode:
authorMathias Stearn <mathias@10gen.com>2010-03-08 16:35:10 -0500
committerMathias Stearn <mathias@10gen.com>2010-03-08 16:39:23 -0500
commitddc9397431f5ece23bfe670752894aa0aae10885 (patch)
treef89e07feb7200c1bf1515460df428dfcd6a415e0 /db/jsobj.cpp
parent53235fdc3667ebd7785788749ca3ec564d6486c6 (diff)
downloadmongo-ddc9397431f5ece23bfe670752894aa0aae10885.tar.gz
Don't escape '/' in JSON strings SERVER-713
Diffstat (limited to 'db/jsobj.cpp')
-rw-r--r--db/jsobj.cpp19
1 files changed, 8 insertions, 11 deletions
diff --git a/db/jsobj.cpp b/db/jsobj.cpp
index 87845c2ccca..2bb813b7533 100644
--- a/db/jsobj.cpp
+++ b/db/jsobj.cpp
@@ -151,7 +151,7 @@ namespace mongo {
return s.str();
}
- string escape( string s ) {
+ string escape( string s , bool escape_slash=false) {
stringstream ret;
for ( string::iterator i = s.begin(); i != s.end(); ++i ) {
switch ( *i ) {
@@ -162,7 +162,7 @@ namespace mongo {
ret << "\\\\";
break;
case '/':
- ret << "\\/";
+ ret << (escape_slash ? "\\/" : "/");
break;
case '\b':
ret << "\\b";
@@ -301,17 +301,13 @@ namespace mongo {
s << " )";
break;
case RegEx:
- if ( format == Strict )
- s << "{ \"$regex\" : \"";
- else
- s << "/";
- s << escape( regex() );
- if ( format == Strict )
+ if ( format == Strict ){
+ s << "{ \"$regex\" : \"" << escape( regex() );
s << "\", \"$options\" : \"" << regexFlags() << "\" }";
- else {
- s << "/";
+ } else {
+ s << "/" << escape( regex() , true ) << "/";
// FIXME Worry about alpha order?
- for ( const char *f = regexFlags(); *f; ++f )
+ for ( const char *f = regexFlags(); *f; ++f ){
switch ( *f ) {
case 'g':
case 'i':
@@ -320,6 +316,7 @@ namespace mongo {
default:
break;
}
+ }
}
break;