Skip to content

Commit

Permalink
JAVA-151: Call _checkObject from Insert() as well as Save() to ensure…
Browse files Browse the repository at this point in the history
… no keys with . are inserted. Test to *expect* an exception.
  • Loading branch information
Brendan W. McAdams committed Dec 9, 2010
1 parent 5538770 commit b83350c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/main/com/mongodb/DBApiLayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,14 @@ protected WriteResult insert(DBObject[] arr, boolean shouldApply , com.mongodb.W
for ( int i=0; i<arr.length; i++ ){
DBObject o=arr[i];
apply( o );
_checkObject( o , false , false );
Object id = o.get( "_id" );
if ( id instanceof ObjectId ){
((ObjectId)id).notNew();
}
}
}

WriteResult last = null;

int cur = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/main/com/mongodb/DBCollection.java
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ protected DBCollection( DB base , String name ){
_options = new Bytes.OptionHolder( _db._options );
}

private DBObject _checkObject( DBObject o , boolean canBeNull , boolean query ){
protected DBObject _checkObject( DBObject o , boolean canBeNull , boolean query ){
if ( o == null ){
if ( canBeNull )
return null;
Expand Down
9 changes: 9 additions & 0 deletions src/test/com/mongodb/DBCollectionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,15 @@ public void testIndexExceptions(){

}

@Test( expectedExceptions = IllegalArgumentException.class )
public void testDotKeysFail() {
DBCollection c = _db.getCollection("testdotkeysFail");
c.drop();

DBObject obj = BasicDBObjectBuilder.start().add("x",1).add("y",2).add("foo.bar","baz").get();
c.insert(obj);
}


final DB _db;

Expand Down

0 comments on commit b83350c

Please sign in to comment.