Skip to content

Commit

Permalink
fix lexNumCmp for middle 0 SERVER-3218
Browse files Browse the repository at this point in the history
  • Loading branch information
erh committed Jun 26, 2011
1 parent 01e8230 commit 800d325
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
3 changes: 2 additions & 1 deletion dbtests/basictests.cpp
Expand Up @@ -406,7 +406,8 @@ namespace BasicTests {
ASSERT_EQUALS( -1, lexNumCmp( "000a", "001a"));
ASSERT_EQUALS( 0, lexNumCmp( "010a", "0010a"));

ASSERT_EQUALS( 1 , lexNumCmp( "a0" , "a00" ) );
ASSERT_EQUALS( -1 , lexNumCmp( "a0" , "a00" ) );
ASSERT_EQUALS( 0 , lexNumCmp( "a.0" , "a.00" ) );
}
};

Expand Down
6 changes: 6 additions & 0 deletions jstests/updatea.js
Expand Up @@ -47,4 +47,10 @@ t.update( {} , { $inc: { "a.10" : 1 } } );
orig.a[10]++;


// SERVER-3218
t.drop()
t.insert({"a":{"c00":1}, 'c':2})
t.update({"c":2}, {'$inc':{'a.c000':1}})

assert.eq( { "c00" : 1 , "c000" : 1 } , t.findOne().a , "D1" )

18 changes: 14 additions & 4 deletions util/stringutils.h
Expand Up @@ -44,6 +44,9 @@ namespace mongo {
// for convenience, '{' is greater than anything and stops number parsing
inline int lexNumCmp( const char *s1, const char *s2 ) {
//cout << "START : " << s1 << "\t" << s2 << endl;

bool startWord = true;

while( *s1 && *s2 ) {

bool p1 = ( *s1 == (char)255 );
Expand All @@ -59,8 +62,11 @@ namespace mongo {

if ( n1 && n2 ) {
// get rid of leading 0s
while ( *s1 == '0' ) s1++;
while ( *s2 == '0' ) s2++;
if ( startWord ) {
while ( *s1 == '0' ) s1++;
while ( *s2 == '0' ) s2++;
startWord = false;
}

char * e1 = (char*)s1;
char * e2 = (char*)s2;
Expand Down Expand Up @@ -91,7 +97,7 @@ namespace mongo {
s2 = e2;
continue;
}

if ( n1 )
return 1;

Expand All @@ -103,7 +109,11 @@ namespace mongo {

if ( *s2 > *s1 )
return -1;


if ( *s1 == '.' )
startWord = true;
else
startWord = false;
s1++; s2++;
}

Expand Down

0 comments on commit 800d325

Please sign in to comment.