Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

SERVER-3370 SERVER-3218 backport lexNumCmp fixes to 1.8

  • Loading branch information...
commit e82f9ddc53a4fe24a40f190b45dc25b7ed88ed96 1 parent 57fa5f2
astaple astaple authored
21 dbtests/basictests.cpp
@@ -399,6 +399,27 @@ namespace BasicTests {
399 399 ASSERT_EQUALS( -1, lexNumCmp( "a", "0a"));
400 400 ASSERT_EQUALS( -1, lexNumCmp( "000a", "001a"));
401 401 ASSERT_EQUALS( 0, lexNumCmp( "010a", "0010a"));
  402 +
  403 + ASSERT_EQUALS( -1 , lexNumCmp( "a0" , "a00" ) );
  404 + ASSERT_EQUALS( 0 , lexNumCmp( "a.0" , "a.00" ) );
  405 + ASSERT_EQUALS( -1 , lexNumCmp( "a.b.c.d0" , "a.b.c.d00" ) );
  406 + ASSERT_EQUALS( 1 , lexNumCmp( "a.b.c.0.y" , "a.b.c.00.x" ) );
  407 +
  408 + ASSERT_EQUALS( -1, lexNumCmp( "a", "a-" ) );
  409 + ASSERT_EQUALS( 1, lexNumCmp( "a-", "a" ) );
  410 + ASSERT_EQUALS( 0, lexNumCmp( "a-", "a-" ) );
  411 +
  412 + ASSERT_EQUALS( -1, lexNumCmp( "a", "a-c" ) );
  413 + ASSERT_EQUALS( 1, lexNumCmp( "a-c", "a" ) );
  414 + ASSERT_EQUALS( 0, lexNumCmp( "a-c", "a-c" ) );
  415 +
  416 + ASSERT_EQUALS( 1, lexNumCmp( "a-c.t", "a.t" ) );
  417 + ASSERT_EQUALS( -1, lexNumCmp( "a.t", "a-c.t" ) );
  418 + ASSERT_EQUALS( 0, lexNumCmp( "a-c.t", "a-c.t" ) );
  419 +
  420 + ASSERT_EQUALS( 1, lexNumCmp( "ac.t", "a.t" ) );
  421 + ASSERT_EQUALS( -1, lexNumCmp( "a.t", "ac.t" ) );
  422 + ASSERT_EQUALS( 0, lexNumCmp( "ac.t", "ac.t" ) );
402 423 }
403 424 };
404 425
6 jstests/updatea.js
@@ -46,5 +46,9 @@ assert.eq( orig , t.findOne() , "C2" );
46 46 t.update( {} , { $inc: { "a.10" : 1 } } );
47 47 orig.a[10]++;
48 48
  49 +// SERVER-3218
  50 +t.drop()
  51 +t.insert({"a":{"c00":1}, 'c':2})
  52 +t.update({"c":2}, {'$inc':{'a.c000':1}})
49 53
50   -
  54 +assert.eq( { "c00" : 1 , "c000" : 1 } , t.findOne().a , "D1" )
17 jstests/updateg.js
... ... @@ -0,0 +1,17 @@
  1 +// SERVER-3370 check modifiers with field name characters comparing less than '.' character.
  2 +
  3 +t = db.jstests_updateg;
  4 +
  5 +t.drop();
  6 +t.update({}, { '$inc' : { 'all.t' : 1, 'all-copy.t' : 1 }}, true);
  7 +assert.eq( 1, t.count( {all:{t:1},'all-copy':{t:1}} ) );
  8 +
  9 +t.drop();
  10 +t.save({ 'all' : {}, 'all-copy' : {}});
  11 +t.update({}, { '$inc' : { 'all.t' : 1, 'all-copy.t' : 1 }});
  12 +assert.eq( 1, t.count( {all:{t:1},'all-copy':{t:1}} ) );
  13 +
  14 +t.drop();
  15 +t.save({ 'all11' : {}, 'all2' : {}});
  16 +t.update({}, { '$inc' : { 'all11.t' : 1, 'all2.t' : 1 }});
  17 +assert.eq( 1, t.count( {all11:{t:1},'all2':{t:1}} ) );
29 util/goodies.h
@@ -486,11 +486,30 @@ namespace mongo {
486 486 return x;
487 487 }
488 488
489   - // for convenience, '{' is greater than anything and stops number parsing
  489 + /**
  490 + * Non numeric characters are compared lexicographically; numeric substrings
  491 + * are compared numerically; dots separate ordered comparable subunits.
  492 + * For convenience, character 255 is greater than anything else.
  493 + */
490 494 inline int lexNumCmp( const char *s1, const char *s2 ) {
491 495 //cout << "START : " << s1 << "\t" << s2 << endl;
  496 +
  497 + bool startWord = true;
  498 +
492 499 while( *s1 && *s2 ) {
493 500
  501 + bool d1 = ( *s1 == '.' );
  502 + bool d2 = ( *s2 == '.' );
  503 + if ( d1 && !d2 )
  504 + return -1;
  505 + if ( d2 && !d1 )
  506 + return 1;
  507 + if ( d1 && d2 ) {
  508 + ++s1; ++s2;
  509 + startWord = true;
  510 + continue;
  511 + }
  512 +
494 513 bool p1 = ( *s1 == (char)255 );
495 514 bool p2 = ( *s2 == (char)255 );
496 515 //cout << "\t\t " << p1 << "\t" << p2 << endl;
@@ -504,8 +523,10 @@ namespace mongo {
504 523
505 524 if ( n1 && n2 ) {
506 525 // get rid of leading 0s
507   - while ( *s1 == '0' ) s1++;
508   - while ( *s2 == '0' ) s2++;
  526 + if ( startWord ) {
  527 + while ( *s1 == '0' ) s1++;
  528 + while ( *s2 == '0' ) s2++;
  529 + }
509 530
510 531 char * e1 = (char*)s1;
511 532 char * e2 = (char*)s2;
@@ -534,6 +555,7 @@ namespace mongo {
534 555 // otherwise, the numbers are equal
535 556 s1 = e1;
536 557 s2 = e2;
  558 + startWord = false;
537 559 continue;
538 560 }
539 561
@@ -550,6 +572,7 @@ namespace mongo {
550 572 return -1;
551 573
552 574 s1++; s2++;
  575 + startWord = false;
553 576 }
554 577
555 578 if ( *s1 )

0 comments on commit e82f9dd

Please sign in to comment.
Something went wrong with that request. Please try again.