File tree Expand file tree Collapse file tree 2 files changed +22
-2
lines changed
tests/MongoDB.Bson.Tests/IO Expand file tree Collapse file tree 2 files changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -1961,13 +1961,13 @@ private BsonValue ParseTimestampConstructor()
1961
1961
VerifyToken ( "," ) ;
1962
1962
int increment ;
1963
1963
var incrementToken = PopToken ( ) ;
1964
- if ( secondsSinceEpochToken . IsNumber )
1964
+ if ( incrementToken . IsNumber )
1965
1965
{
1966
1966
increment = incrementToken . Int32Value ;
1967
1967
}
1968
1968
else
1969
1969
{
1970
- var message = string . Format ( "JSON reader expected a number but found '{0}'." , secondsSinceEpochToken . Lexeme ) ;
1970
+ var message = string . Format ( "JSON reader expected a number but found '{0}'." , incrementToken . Lexeme ) ;
1971
1971
throw new FormatException ( message ) ;
1972
1972
}
1973
1973
VerifyToken ( ")" ) ;
Original file line number Diff line number Diff line change @@ -1396,6 +1396,26 @@ public void TestTimestampConstructor()
1396
1396
Assert . Equal ( json , BsonSerializer . Deserialize < BsonTimestamp > ( new StringReader ( json ) ) . ToJson ( ) ) ;
1397
1397
}
1398
1398
1399
+ [ Theory ]
1400
+ // truncated input
1401
+ [ InlineData ( "Timestamp(" ) ]
1402
+ [ InlineData ( "Timestamp()" ) ]
1403
+ [ InlineData ( "Timestamp(1" ) ]
1404
+ [ InlineData ( "Timestamp(1," ) ]
1405
+ [ InlineData ( "Timestamp(1, 2" ) ]
1406
+ // valid JSON but not a valid extended JSON BsonTimestamp
1407
+ [ InlineData ( "Timestamp('abc', 2)" ) ]
1408
+ [ InlineData ( "Timestamp(2, 'abc')" ) ]
1409
+ public void TestTimestampConstructorWhenInvalid ( string json )
1410
+ {
1411
+ using ( _bsonReader = new JsonReader ( json ) )
1412
+ {
1413
+ var exception = Record . Exception ( ( ) => _bsonReader . ReadBsonType ( ) ) ;
1414
+
1415
+ exception . Should ( ) . BeOfType < FormatException > ( ) ;
1416
+ }
1417
+ }
1418
+
1399
1419
[ Theory ]
1400
1420
[ InlineData ( "{ \" $timestamp\" : { \" t\" : 1, \" i\" : 2 } }" ) ]
1401
1421
[ InlineData ( "{ \" $timestamp\" : { \" i\" : 2, \" t\" : 1 } }" ) ]
You can’t perform that action at this time.
0 commit comments