summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEliot Horowitz <eliot@10gen.com>2010-04-02 15:56:43 -0400
committerEliot Horowitz <eliot@10gen.com>2010-04-02 15:56:43 -0400
commit44237031b1c0edec4ffc931aad1b8914de53ad5e (patch)
tree74eb3f2455d75a9ddc09c3608c0cd7ca2159bbe6
parent16718fe78555180bf4da08bfa9a966642966a13e (diff)
downloadmongo-44237031b1c0edec4ffc931aad1b8914de53ad5e.tar.gz
make return parsing smarter SERVER-864
-rw-r--r--jstests/where3.js10
-rw-r--r--scripting/engine_spidermonkey.cpp10
2 files changed, 18 insertions, 2 deletions
diff --git a/jstests/where3.js b/jstests/where3.js
new file mode 100644
index 00000000000..c062ed11513
--- /dev/null
+++ b/jstests/where3.js
@@ -0,0 +1,10 @@
+
+t = db.where3;
+t.drop()
+
+t.save( { returned_date : 5 } );
+t.save( { returned_date : 6 } );
+
+assert.eq( 1 , t.find( function(){ return this.returned_date == 5; } ).count() , "A" );
+assert.eq( 1 , t.find( { $where : "return this.returned_date == 5;" } ).count() , "B" );
+assert.eq( 1 , t.find( { $where : "this.returned_date == 5;" } ).count() , "C" );
diff --git a/scripting/engine_spidermonkey.cpp b/scripting/engine_spidermonkey.cpp
index df99f636ea1..fd76dea7a87 100644
--- a/scripting/engine_spidermonkey.cpp
+++ b/scripting/engine_spidermonkey.cpp
@@ -382,8 +382,14 @@ namespace mongo {
}
bool isSimpleStatement( const string& code ){
- if ( code.find( "return" ) != string::npos )
- return false;
+ {
+ size_t x = code.find( "return" );
+ if ( x != string::npos ){
+ if ( ( x == 0 || ! isalpha( code[x-1] ) ) &&
+ ! isalpha( code[x+6] ) )
+ return false;
+ }
+ }
if ( code.find( ";" ) != string::npos &&
code.find( ";" ) != code.rfind( ";" ) )