@@ -1109,16 +1109,14 @@ public void TestLenientRead()
1109
1109
1110
1110
var document = new BsonDocument { { "_id" , ObjectId . GenerateNewId ( ) } , { "x" , "abc" } } ;
1111
1111
var bson = document . ToBson ( ) ;
1112
- bson [ 28 ] = 0xed ; // replace "abc" with 0xeda0db which is not valid UTF8
1113
- bson [ 29 ] = 0xa0 ;
1114
- bson [ 30 ] = 0xdb ;
1112
+ bson [ 28 ] = 0xc0 ; // replace 'a' with invalid lone first code point (not followed by 10xxxxxx)
1115
1113
1116
1114
// use a RawBsonDocument to sneak the invalid bytes into the database
1117
1115
var rawBsonDocument = new RawBsonDocument ( bson ) ;
1118
1116
collection . Insert ( rawBsonDocument ) ;
1119
1117
1120
1118
var rehydrated = collection . FindOne ( Query . EQ ( "_id" , document [ "_id" ] ) ) ;
1121
- Assert . AreEqual ( "\ufffd \ufffd " , rehydrated [ "x" ] . AsString ) ;
1119
+ Assert . AreEqual ( "\ufffd " + "bc ", rehydrated [ "x" ] . AsString ) ;
1122
1120
}
1123
1121
1124
1122
[ Test ]
@@ -1127,7 +1125,7 @@ public void TestLenientWrite()
1127
1125
var settings = new MongoCollectionSettings { WriteEncoding = new UTF8Encoding ( false , false ) } ;
1128
1126
var collection = _database . GetCollection ( Configuration . TestCollection . Name , settings ) ;
1129
1127
1130
- var document = new BsonDocument ( "x" , "\ud83d " ) ;
1128
+ var document = new BsonDocument ( "x" , "\udc00 " ) ; // invalid lone low surrogate
1131
1129
collection . Save ( document ) ;
1132
1130
1133
1131
var rehydrated = collection . FindOne ( Query . EQ ( "_id" , document [ "_id" ] ) ) ;
@@ -1495,9 +1493,7 @@ public void TestStrictRead()
1495
1493
1496
1494
var document = new BsonDocument { { "_id" , ObjectId . GenerateNewId ( ) } , { "x" , "abc" } } ;
1497
1495
var bson = document . ToBson ( ) ;
1498
- bson [ 28 ] = 0xed ; // replace "abc" with 0xeda0db which is not valid UTF8
1499
- bson [ 29 ] = 0xa0 ;
1500
- bson [ 30 ] = 0xdb ;
1496
+ bson [ 28 ] = 0xc0 ; // replace 'a' with invalid lone first code point (not followed by 10xxxxxx)
1501
1497
1502
1498
// use a RawBsonDocument to sneak the invalid bytes into the database
1503
1499
var rawBsonDocument = new RawBsonDocument ( bson ) ;
@@ -1512,7 +1508,7 @@ public void TestStrictWrite()
1512
1508
var settings = new MongoCollectionSettings { WriteEncoding = new UTF8Encoding ( false , true ) } ;
1513
1509
var collection = _database . GetCollection ( Configuration . TestCollection . Name , settings ) ;
1514
1510
1515
- var document = new BsonDocument ( "x" , "\ud83d " ) ;
1511
+ var document = new BsonDocument ( "x" , "\udc00 " ) ; // invalid lone low surrogate
1516
1512
Assert . Throws < EncoderFallbackException > ( ( ) => { collection . Insert ( document ) ; } ) ;
1517
1513
}
1518
1514
0 commit comments