summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEliot Horowitz <eliot@10gen.com>2009-08-17 10:46:44 -0400
committerEliot Horowitz <eliot@10gen.com>2009-08-17 10:46:44 -0400
commit3c93f8e57564c18bd1076cf459296a4f4226b7ef (patch)
treea7256d87595e8e4439a84d4c7528db7f7be959cc
parent3c651482c420357f1d01303d0c8dc733a6a9c21d (diff)
downloadmongo-3c93f8e57564c18bd1076cf459296a4f4226b7ef.tar.gz
fixed BSONElement::simpleRegex and changed return to a string. this fixes SERVER-239
-rw-r--r--db/jsobj.cpp25
-rw-r--r--db/jsobj.h5
-rw-r--r--db/queryutil.cpp4
-rw-r--r--jstests/regex3.js2
4 files changed, 23 insertions, 13 deletions
diff --git a/db/jsobj.cpp b/db/jsobj.cpp
index f6153509432..9c823dae7f9 100644
--- a/db/jsobj.cpp
+++ b/db/jsobj.cpp
@@ -532,20 +532,27 @@ namespace mongo {
return -1;
}
- const char *BSONElement::simpleRegex() const {
+ string BSONElement::simpleRegex() const {
if ( *regexFlags() )
- return 0;
+ return "";
+
const char *i = regex();
if ( *i != '^' )
- return 0;
- ++i;
+ return "";
+ ++i;
// Empty string matches everything, won't limit our search.
if ( !*i )
- return 0;
- for( ; *i; ++i )
- if (!( *i == ' ' || (*i>='0'&&*i<='9') || (*i>='@'&&*i<='Z') || (*i>='a'&&*i<='z') ))
- return 0;
- return regex() + 1;
+ return 0;
+
+ stringstream ss;
+ for( ; *i; ++i ){
+ if ( *i == ' ' || (*i>='0'&&*i<='9') || (*i>='@'&&*i<='Z') || (*i>='a'&&*i<='z') )
+ ss << *i;
+ else
+ break;
+ }
+
+ return ss.str();
}
void BSONElement::validate() const {
diff --git a/db/jsobj.h b/db/jsobj.h
index c3d87c83ff3..1d07665337b 100644
--- a/db/jsobj.h
+++ b/db/jsobj.h
@@ -429,7 +429,10 @@ namespace mongo {
assert(type() == RegEx);
return value();
}
- const char *simpleRegex() const;
+
+ /** returns a regex that when used as a matcher, would return a super set of regex() */
+ string simpleRegex() const;
+
/** Retrieve the regex flags (options) for a Regex element */
const char *regexFlags() const {
const char *p = regex();
diff --git a/db/queryutil.cpp b/db/queryutil.cpp
index 501de5f4f2d..48c2e03bf8c 100644
--- a/db/queryutil.cpp
+++ b/db/queryutil.cpp
@@ -32,8 +32,8 @@ namespace mongo {
if ( e.eoo() )
return;
if ( e.type() == RegEx ) {
- const char *r = e.simpleRegex();
- if ( r ) {
+ const string r = e.simpleRegex();
+ if ( r.size() ) {
lower() = addObj( BSON( "" << r ) ).firstElement();
upper() = addObj( BSON( "" << simpleRegexEnd( r ) ) ).firstElement();
upperInclusive() = false;
diff --git a/jstests/regex3.js b/jstests/regex3.js
index 17d0cdbba82..5fb9810aeac 100644
--- a/jstests/regex3.js
+++ b/jstests/regex3.js
@@ -11,4 +11,4 @@ assert.eq( 2 , t.find( { name : /^e.*/ } ).count() , "no index count" );
assert.eq( 4 , t.find( { name : /^e.*/ } ).explain().nscanned , "no index explain" );
t.ensureIndex( { name : 1 } );
assert.eq( 2 , t.find( { name : /^e.*/ } ).count() , "index count" );
-//assert.eq( 2 , t.find( { name : /^e.*/ } ).explain().nscanned , "index explain" ); // SERVER-239
+assert.eq( 2 , t.find( { name : /^e.*/ } ).explain().nscanned , "index explain" ); // SERVER-239