mirror of
https://github.com/mongodb/mongo.git
synced 2024-11-30 09:06:21 +01:00
fix lexNumCmp with magic end of marker
This commit is contained in:
parent
666af2a1b9
commit
c78415729e
@ -517,10 +517,12 @@ namespace mongo {
|
|||||||
DEBUGUPDATE( "\t\t createNewFromMods root: " << root );
|
DEBUGUPDATE( "\t\t createNewFromMods root: " << root );
|
||||||
BSONObjIteratorSorted es( obj );
|
BSONObjIteratorSorted es( obj );
|
||||||
BSONElement e = es.next();
|
BSONElement e = es.next();
|
||||||
|
|
||||||
ModStateHolder::iterator m = _mods.lower_bound( root );
|
ModStateHolder::iterator m = _mods.lower_bound( root );
|
||||||
ModStateHolder::iterator mend = _mods.lower_bound( root + (char)254 );
|
StringBuilder buf(root.size() + 2 );
|
||||||
|
buf << root << (char)255;
|
||||||
|
ModStateHolder::iterator mend = _mods.lower_bound( buf.str() );
|
||||||
|
|
||||||
set<string> onedownseen;
|
set<string> onedownseen;
|
||||||
|
|
||||||
while ( e.type() && m != mend ){
|
while ( e.type() && m != mend ){
|
||||||
|
@ -319,6 +319,9 @@ namespace BasicTests {
|
|||||||
class LexNumCmp {
|
class LexNumCmp {
|
||||||
public:
|
public:
|
||||||
void run() {
|
void run() {
|
||||||
|
|
||||||
|
ASSERT( ! isNumber( (char)255 ) );
|
||||||
|
|
||||||
ASSERT_EQUALS( 0, lexNumCmp( "a", "a" ) );
|
ASSERT_EQUALS( 0, lexNumCmp( "a", "a" ) );
|
||||||
ASSERT_EQUALS( -1, lexNumCmp( "a", "aa" ) );
|
ASSERT_EQUALS( -1, lexNumCmp( "a", "aa" ) );
|
||||||
ASSERT_EQUALS( 1, lexNumCmp( "aa", "a" ) );
|
ASSERT_EQUALS( 1, lexNumCmp( "aa", "a" ) );
|
||||||
@ -346,7 +349,7 @@ namespace BasicTests {
|
|||||||
ASSERT_EQUALS( -1, lexNumCmp( "f12f", "f12g" ) );
|
ASSERT_EQUALS( -1, lexNumCmp( "f12f", "f12g" ) );
|
||||||
ASSERT_EQUALS( 1, lexNumCmp( "f12g", "f12f" ) );
|
ASSERT_EQUALS( 1, lexNumCmp( "f12g", "f12f" ) );
|
||||||
ASSERT_EQUALS( 1, lexNumCmp( "aa{", "aab" ) );
|
ASSERT_EQUALS( 1, lexNumCmp( "aa{", "aab" ) );
|
||||||
ASSERT_EQUALS( 1, lexNumCmp( "aa{", "aa1" ) );
|
ASSERT_EQUALS( -1, lexNumCmp( "aa{", "aa1" ) );
|
||||||
ASSERT_EQUALS( -1, lexNumCmp( "a1{", "a11" ) );
|
ASSERT_EQUALS( -1, lexNumCmp( "a1{", "a11" ) );
|
||||||
ASSERT_EQUALS( 1, lexNumCmp( "a1{a", "a1{" ) );
|
ASSERT_EQUALS( 1, lexNumCmp( "a1{a", "a1{" ) );
|
||||||
ASSERT_EQUALS( -1, lexNumCmp( "a1{", "a1{a" ) );
|
ASSERT_EQUALS( -1, lexNumCmp( "a1{", "a1{a" ) );
|
||||||
@ -355,6 +358,10 @@ namespace BasicTests {
|
|||||||
|
|
||||||
ASSERT_EQUALS( -1 , lexNumCmp( "a.0" , "a.1" ) );
|
ASSERT_EQUALS( -1 , lexNumCmp( "a.0" , "a.1" ) );
|
||||||
ASSERT_EQUALS( -1 , lexNumCmp( "a.0.b" , "a.1" ) );
|
ASSERT_EQUALS( -1 , lexNumCmp( "a.0.b" , "a.1" ) );
|
||||||
|
|
||||||
|
ASSERT_EQUALS( -1 , lexNumCmp( "b." , "b.|" ) );
|
||||||
|
ASSERT_EQUALS( -1 , lexNumCmp( "b.0e" , (string("b.") + (char)255).c_str() ) );
|
||||||
|
ASSERT_EQUALS( -1 , lexNumCmp( "b." , "b.0e" ) );
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -652,15 +652,17 @@ namespace mongo {
|
|||||||
|
|
||||||
// for convenience, '{' is greater than anything and stops number parsing
|
// for convenience, '{' is greater than anything and stops number parsing
|
||||||
inline int lexNumCmp( const char *s1, const char *s2 ) {
|
inline int lexNumCmp( const char *s1, const char *s2 ) {
|
||||||
|
//cout << "START : " << s1 << "\t" << s2 << endl;
|
||||||
while( *s1 && *s2 ) {
|
while( *s1 && *s2 ) {
|
||||||
|
|
||||||
bool p1 = ( *s1 == '{' );
|
bool p1 = ( *s1 == (char)255 );
|
||||||
bool p2 = ( *s2 == '{' );
|
bool p2 = ( *s2 == (char)255 );
|
||||||
|
//cout << "\t\t " << p1 << "\t" << p2 << endl;
|
||||||
if ( p1 && !p2 )
|
if ( p1 && !p2 )
|
||||||
return 1;
|
return 1;
|
||||||
if ( p2 && !p1 )
|
if ( p2 && !p1 )
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
bool n1 = isNumber( *s1 );
|
bool n1 = isNumber( *s1 );
|
||||||
bool n2 = isNumber( *s2 );
|
bool n2 = isNumber( *s2 );
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user