0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 09:32:32 +01:00

make return parsing smarter SERVER-864

This commit is contained in:
Eliot Horowitz 2010-04-02 15:56:43 -04:00
parent 16718fe785
commit 44237031b1
2 changed files with 18 additions and 2 deletions

10
jstests/where3.js Normal file
View File

@ -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" );

View File

@ -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( ";" ) )