diff --git a/db/queryutil.cpp b/db/queryutil.cpp index 5a7446717f060..aecf76031c20e 100644 --- a/db/queryutil.cpp +++ b/db/queryutil.cpp @@ -181,10 +181,12 @@ namespace mongo { if ( e.eoo() ) return; + int op = e.getGtLtOp(); if ( e.type() == RegEx || (e.type() == Object && !e.embeddedObject()["$regex"].eoo()) ) { + uassert( 13454, "invalid regular expression operator", op == BSONObj::Equality || op == BSONObj::opREGEX ); if ( !isNot ) { // no optimization for negated regex - we could consider creating 2 intervals comprising all nonmatching prefixes const string r = simpleRegex(e); if ( r.size() ) { @@ -216,7 +218,6 @@ namespace mongo { } return; } - int op = e.getGtLtOp(); if ( isNot ) { switch( op ) { case BSONObj::Equality: diff --git a/jstests/ne2.js b/jstests/ne2.js index c61ed193a1bcc..89e99aa668e3a 100644 --- a/jstests/ne2.js +++ b/jstests/ne2.js @@ -19,25 +19,3 @@ e = t.find( { a: { $gt: -1, $lt: 1, $ne: 0 } } ).explain(); assert.eq( "BtreeCursor a_1 multi", e.cursor ); assert.eq( { a: [ [ -1, 0 ], [ 0, 1 ] ] }, e.indexBounds ); assert.eq( 3, e.nscanned ); - -//e = t.find( { a: { $not: { $all: [0] }} } ).explain( true ); -//assert.eq( "BtreeCursor a_1 multi", e.cursor ); -//assert.eq( 0, e.indexBounds.a[ 0 ][ 1 ] ); -//assert.eq( 0, e.indexBounds.a[ 1 ][ 0 ] ); -//assert.eq( 3, e.nscanned ); -// -//e = t.find( { a: { $gt: -1, $lt: 1, $not: { $all: [ 0 ] } } } ).explain(); -//assert.eq( "BtreeCursor a_1 multi", e.cursor ); -//assert.eq( { a: [ [ -1, 0 ], [ 0, 1 ] ] }, e.indexBounds ); -//assert.eq( 3, e.nscanned ); -// -//e = t.find( { a: { $nin: [ 0 ] } } ).explain( true ); -//assert.eq( "BtreeCursor a_1 multi", e.cursor ); -//assert.eq( 0, e.indexBounds.a[ 0 ][ 1 ] ); -//assert.eq( 0, e.indexBounds.a[ 1 ][ 0 ] ); -//assert.eq( 3, e.nscanned ); -// -//e = t.find( { a: { $gt: -1, $lt: 1, $nin: [ 0 ] } } ).explain(); -//assert.eq( "BtreeCursor a_1 multi", e.cursor ); -//assert.eq( { a: [ [ -1, 0 ], [ 0, 1 ] ] }, e.indexBounds ); -//assert.eq( 3, e.nscanned ); diff --git a/jstests/ne3.js b/jstests/ne3.js new file mode 100644 index 0000000000000..489f47aec0d8a --- /dev/null +++ b/jstests/ne3.js @@ -0,0 +1,12 @@ +// don't allow most operators with regex + +t = db.jstests_ne3; +t.drop(); + +assert.throws( function() { t.findOne( { t: { $ne: /a/ } } ); } ); +assert.throws( function() { t.findOne( { t: { $gt: /a/ } } ); } ); +assert.throws( function() { t.findOne( { t: { $gte: /a/ } } ); } ); +assert.throws( function() { t.findOne( { t: { $lt: /a/ } } ); } ); +assert.throws( function() { t.findOne( { t: { $lte: /a/ } } ); } ); + +assert.eq( 0, t.count( { t: { $in: [ /a/ ] } } ) ); \ No newline at end of file diff --git a/jstests/regex9.js b/jstests/regex9.js index 559efd9f3cc5b..896855c6dfbe7 100644 --- a/jstests/regex9.js +++ b/jstests/regex9.js @@ -1,5 +1,5 @@ -t = db.regex3; +t = db.regex9; t.drop(); t.insert( { _id : 1 , a : [ "a" , "b" , "c" ] } ) diff --git a/mongo.xcodeproj/project.pbxproj b/mongo.xcodeproj/project.pbxproj index 6da0def88bab4..d3c6e3f5b09a8 100644 --- a/mongo.xcodeproj/project.pbxproj +++ b/mongo.xcodeproj/project.pbxproj @@ -463,6 +463,8 @@ 938A7A480F54873600FB7A07 /* reccache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = reccache.h; sourceTree = ""; }; 938A7A490F54873600FB7A07 /* reci.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = reci.h; sourceTree = ""; }; 938A7A4A0F54873600FB7A07 /* recstore.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = recstore.h; sourceTree = ""; }; + 938D48DB122C87A2001D83EE /* nin2.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = nin2.js; sourceTree = ""; }; + 938D493D122C99A3001D83EE /* ne3.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = ne3.js; sourceTree = ""; }; 938E5EB3110E1ED700A8760A /* repair.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = repair.js; sourceTree = ""; }; 938E60AC110F734800A8760A /* directoryperdb.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = directoryperdb.js; sourceTree = ""; }; 938E639B110FC66900A8760A /* auth1.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = auth1.js; sourceTree = ""; }; @@ -836,6 +838,8 @@ 934BEB9A10DFFA9600178102 /* jstests */ = { isa = PBXGroup; children = ( + 938D493D122C99A3001D83EE /* ne3.js */, + 938D48DB122C87A2001D83EE /* nin2.js */, 939329BF12244845005EB75E /* ne2.js */, 93C46E64121A086500382E61 /* indexj.js */, 93C46E021219AB8E00382E61 /* update_arraymatch6.js */,