mirror of
https://github.com/mongodb/mongo.git
synced 2024-12-01 09:32:32 +01:00
SERVER-652 simplify field name upper limit check, guard against setting string fields in arrays
This commit is contained in:
parent
bbbe0aaf31
commit
246109cc18
@ -1702,7 +1702,9 @@ namespace mongo {
|
||||
|
||||
private:
|
||||
void fill( const char *name ) {
|
||||
int n = strtol( name, NULL, 10 );
|
||||
char *r;
|
||||
int n = strtol( name, &r, 10 );
|
||||
uassert( 13047, "can't append to array using string field name", !*r );
|
||||
while( _i < n )
|
||||
append( nullElt() );
|
||||
}
|
||||
|
@ -469,14 +469,7 @@ namespace mongo {
|
||||
BSONElement e = es.next();
|
||||
|
||||
ModStateHolder::iterator m = _mods.lower_bound( root );
|
||||
ModStateHolder::iterator mend;
|
||||
if ( root.length() == 0 ) {
|
||||
mend = _mods.end();
|
||||
} else {
|
||||
string rootEnd = root;
|
||||
rootEnd[ rootEnd.length() - 1 ]++;
|
||||
mend = _mods.lower_bound( rootEnd );
|
||||
}
|
||||
ModStateHolder::iterator mend = _mods.lower_bound( root + '{' );
|
||||
|
||||
set<string> onedownseen;
|
||||
|
||||
@ -517,7 +510,7 @@ namespace mongo {
|
||||
m++;
|
||||
continue;
|
||||
case RIGHT_BEFORE: // field that doesn't have a MOD
|
||||
b.append( e ); //careful, need to fill?
|
||||
b.append( e ); // if array, ignore field name
|
||||
e = es.next();
|
||||
continue;
|
||||
case RIGHT_SUBFIELD:
|
||||
@ -530,7 +523,7 @@ namespace mongo {
|
||||
|
||||
// finished looping the mods, just adding the rest of the elements
|
||||
while ( e.type() ){
|
||||
b.append( e ); //careful, need to fill?
|
||||
b.append( e ); // if array, ignore field name
|
||||
e = es.next();
|
||||
}
|
||||
|
||||
|
@ -304,6 +304,11 @@ namespace BasicTests {
|
||||
ASSERT_EQUALS( 1, lexNumCmp( "f111", "f11f" ) );
|
||||
ASSERT_EQUALS( -1, lexNumCmp( "f12f", "f12g" ) );
|
||||
ASSERT_EQUALS( 1, lexNumCmp( "f12g", "f12f" ) );
|
||||
ASSERT_EQUALS( 1, lexNumCmp( "aa{", "aab" ) );
|
||||
ASSERT_EQUALS( 1, lexNumCmp( "aa{", "aa1" ) );
|
||||
ASSERT_EQUALS( 1, lexNumCmp( "a1{", "a11" ) );
|
||||
ASSERT_EQUALS( 1, lexNumCmp( "a1{a", "a1{" ) );
|
||||
ASSERT_EQUALS( -1, lexNumCmp( "a1{", "a1{a" ) );
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -24,7 +24,17 @@ t.save( {a:[0,1,2,3,4,5,6,7,8,9,10]} );
|
||||
t.update( {}, {$set:{"a.11":11} } );
|
||||
assert.eq( [0,1,2,3,4,5,6,7,8,9,10,11], t.findOne().a );
|
||||
|
||||
// creating new object w/ number field name (from mods)
|
||||
// create new from query
|
||||
t.drop();
|
||||
t.save( {} );
|
||||
t.update( {}, {$set:{"a.0":4}} );
|
||||
assert.eq( {"0":4}, t.findOne().a );
|
||||
|
||||
// try to set string field in existing array
|
||||
t.drop();
|
||||
t.update( {"a.0":4}, {$set:{b:1}}, true );
|
||||
assert.eq( {"0":4}, t.findOne().a );
|
||||
|
||||
t.drop();
|
||||
t.save( {a:[]} );
|
||||
t.update( {}, {$set:{"a.f":1}} );
|
||||
assert( db.getLastError() );
|
||||
assert.eq( [], t.findOne().a );
|
||||
|
@ -561,9 +561,16 @@ namespace mongo {
|
||||
return c >= '0' && c <= '9';
|
||||
}
|
||||
|
||||
// for convenience, '{' is greater than anything and stops number parsing
|
||||
inline int lexNumCmp( const char *s1, const char *s2 ) {
|
||||
int nret = 0;
|
||||
while( *s1 && *s2 ) {
|
||||
bool p1 = ( *s1 == '{' );
|
||||
bool p2 = ( *s2 == '{' );
|
||||
if ( p1 && !p2 )
|
||||
return 1;
|
||||
if ( p2 && !p1 )
|
||||
return -1;
|
||||
bool n1 = isNumber( *s1 );
|
||||
bool n2 = isNumber( *s2 );
|
||||
if ( n1 && n2 ) {
|
||||
|
Loading…
Reference in New Issue
Block a user