Permalink
Browse files

fix lexNumCmp for middle 0 SERVER-3218

  • Loading branch information...
1 parent 01e8230 commit 800d32536ba0a47518e53d855cbfc30ee0db265c @erh erh committed Jun 26, 2011
Showing with 22 additions and 5 deletions.
  1. +2 −1 dbtests/basictests.cpp
  2. +6 −0 jstests/updatea.js
  3. +14 −4 util/stringutils.h
View
@@ -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" ) );
}
};
View
@@ -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" )
View
@@ -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 );
@@ -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;
@@ -91,7 +97,7 @@ namespace mongo {
s2 = e2;
continue;
}
-
+
if ( n1 )
return 1;
@@ -103,7 +109,11 @@ namespace mongo {
if ( *s2 > *s1 )
return -1;
-
+
+ if ( *s1 == '.' )
+ startWord = true;
+ else
+ startWord = false;
s1++; s2++;
}

0 comments on commit 800d325

Please sign in to comment.