File tree Expand file tree Collapse file tree 2 files changed +39
-0
lines changed
tests/MongoDB.Bson.Tests/Specifications/bson-corpus/tests Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -1357,6 +1357,7 @@ private BsonType ParseExtendedJson()
1357
1357
case "$symbol" : _currentValue = ParseSymbolExtendedJson ( ) ; return BsonType . Symbol ;
1358
1358
case "$timestamp" : _currentValue = ParseTimestampExtendedJson ( ) ; return BsonType . Timestamp ;
1359
1359
case "$undefined" : _currentValue = ParseUndefinedExtendedJson ( ) ; return BsonType . Undefined ;
1360
+ case "$uuid" : _currentValue = ParseUuidExtendedJson ( ) ; return BsonType . Binary ;
1360
1361
}
1361
1362
}
1362
1363
ReturnToBookmark ( bookmark ) ;
@@ -2077,6 +2078,28 @@ private BsonValue ParseUndefinedExtendedJson()
2077
2078
return BsonMaxKey . Value ;
2078
2079
}
2079
2080
2081
+ private BsonValue ParseUuidExtendedJson ( )
2082
+ {
2083
+ VerifyToken ( ":" ) ;
2084
+ var uuidToken = PopToken ( ) ;
2085
+ if ( uuidToken . Type != JsonTokenType . String )
2086
+ {
2087
+ var message = string . Format ( "JSON reader expected a string but found '{0}'." , uuidToken . Lexeme ) ;
2088
+ throw new FormatException ( message ) ;
2089
+ }
2090
+ VerifyToken ( "}" ) ;
2091
+
2092
+ var hexString = uuidToken . StringValue . Replace ( "-" , "" ) ;
2093
+ var bytes = BsonUtils . ParseHexString ( hexString ) ;
2094
+ if ( bytes . Length != 16 )
2095
+ {
2096
+ var message = string . Format ( "Invalid $uuid string: '{0}'." , hexString ) ;
2097
+ throw new FormatException ( message ) ;
2098
+ }
2099
+
2100
+ return new BsonBinaryData ( bytes , BsonBinarySubType . UuidStandard ) ;
2101
+ }
2102
+
2080
2103
private BsonValue ParseUUIDConstructor ( string uuidConstructorName )
2081
2104
{
2082
2105
VerifyToken ( "(" ) ;
Original file line number Diff line number Diff line change 39
39
"canonical_bson" : " 1D000000057800100000000473FFD26444B34C6990E8E7D1DFC035D400" ,
40
40
"canonical_extjson" : " {\" x\" : { \" $binary\" : {\" base64\" : \" c//SZESzTGmQ6OfR38A11A==\" , \" subType\" : \" 04\" }}}"
41
41
},
42
+ {
43
+ "description" : " subtype 0x04 UUID" ,
44
+ "canonical_bson" : " 1D000000057800100000000473FFD26444B34C6990E8E7D1DFC035D400" ,
45
+ "canonical_extjson" : " {\" x\" : { \" $binary\" : {\" base64\" : \" c//SZESzTGmQ6OfR38A11A==\" , \" subType\" : \" 04\" }}}" ,
46
+ "degenerate_extjson" : " {\" x\" : { \" $uuid\" : \" 73ffd264-44b3-4c69-90e8-e7d1dfc035d4\" }}"
47
+ },
42
48
{
43
49
"description" : " subtype 0x05" ,
44
50
"canonical_bson" : " 1D000000057800100000000573FFD26444B34C6990E8E7D1DFC035D400" ,
81
87
"description" : " subtype 0x02 length negative one" ,
82
88
"bson" : " 130000000578000600000002FFFFFFFFFFFF00"
83
89
}
90
+ ],
91
+ "parseErrors" : [
92
+ {
93
+ "description" : " $uuid wrong type" ,
94
+ "string" : " {\" x\" : { \" $uuid\" : { \" data\" : \" 73ffd264-44b3-4c69-90e8-e7d1dfc035d4\" }}}"
95
+ },
96
+ {
97
+ "description" : " $uuid invalid value" ,
98
+ "string" : " {\" x\" : { \" $uuid\" : \" 73ffd264-44b3-90e8-e7d1dfc035d4\" }}"
99
+ }
84
100
]
85
101
}
You can’t perform that action at this time.
0 commit comments