Skip to content

Commit

Permalink
SERVER-1705 validate op type with regex
Browse files Browse the repository at this point in the history
  • Loading branch information
astaple committed Aug 31, 2010
1 parent fccae83 commit 30c59fa
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 24 deletions.
3 changes: 2 additions & 1 deletion db/queryutil.cpp
Expand Up @@ -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() ) {
Expand Down Expand Up @@ -216,7 +218,6 @@ namespace mongo {
}
return;
}
int op = e.getGtLtOp();
if ( isNot ) {
switch( op ) {
case BSONObj::Equality:
Expand Down
22 changes: 0 additions & 22 deletions jstests/ne2.js
Expand Up @@ -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 );
12 changes: 12 additions & 0 deletions 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/ ] } } ) );
2 changes: 1 addition & 1 deletion jstests/regex9.js
@@ -1,5 +1,5 @@

t = db.regex3;
t = db.regex9;
t.drop();

t.insert( { _id : 1 , a : [ "a" , "b" , "c" ] } )
Expand Down
4 changes: 4 additions & 0 deletions mongo.xcodeproj/project.pbxproj
Expand Up @@ -463,6 +463,8 @@
938A7A480F54873600FB7A07 /* reccache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = reccache.h; sourceTree = "<group>"; };
938A7A490F54873600FB7A07 /* reci.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = reci.h; sourceTree = "<group>"; };
938A7A4A0F54873600FB7A07 /* recstore.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = recstore.h; sourceTree = "<group>"; };
938D48DB122C87A2001D83EE /* nin2.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = nin2.js; sourceTree = "<group>"; };
938D493D122C99A3001D83EE /* ne3.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = ne3.js; sourceTree = "<group>"; };
938E5EB3110E1ED700A8760A /* repair.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = repair.js; sourceTree = "<group>"; };
938E60AC110F734800A8760A /* directoryperdb.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = directoryperdb.js; sourceTree = "<group>"; };
938E639B110FC66900A8760A /* auth1.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = auth1.js; sourceTree = "<group>"; };
Expand Down Expand Up @@ -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 */,
Expand Down

0 comments on commit 30c59fa

Please sign in to comment.