@@ -786,8 +786,8 @@ extension JSONDecoderImpl: Decoder {
786786
787787 var iter = jsonMap. makeObjectIterator ( from: region. startOffset)
788788 while let ( keyValue, value) = iter. next ( ) {
789- // Failing to unwrap a string here is impossible, as scanning already guarantees that dictionary keys are strings .
790- let key = try ! self . unwrapString ( from: keyValue, for: dictCodingPathNode, _CodingKey? . none)
789+ // We know these values are keys, but UTF-8 decoding could still fail .
790+ let key = try self . unwrapString ( from: keyValue, for: dictCodingPathNode, _CodingKey? . none)
791791 let value = try self . unwrap ( value, as: dictType. elementType, for: dictCodingPathNode, _CodingKey ( stringValue: key) !)
792792 result [ key] . _setIfNil ( to: value)
793793 }
@@ -1202,14 +1202,14 @@ extension JSONDecoderImpl {
12021202 switch keyDecodingStrategy {
12031203 case . useDefaultKeys:
12041204 while let ( keyValue, value) = iter. next ( ) {
1205- // Failing to unwrap a string here is impossible, as scanning already guarantees that dictionary keys are strings .
1206- let key = try ! impl. unwrapString ( from: keyValue, for: codingPathNode, _CodingKey? . none)
1205+ // We know these values are keys, but UTF-8 decoding could still fail .
1206+ let key = try impl. unwrapString ( from: keyValue, for: codingPathNode, _CodingKey? . none)
12071207 result [ key] . _setIfNil ( to: value)
12081208 }
12091209 case . convertFromSnakeCase:
12101210 while let ( keyValue, value) = iter. next ( ) {
1211- // Failing to unwrap a string here is impossible, as scanning already guarantees that dictionary keys are strings .
1212- let key = try ! impl. unwrapString ( from: keyValue, for: codingPathNode, _CodingKey? . none)
1211+ // We know these values are keys, but UTF-8 decoding could still fail .
1212+ let key = try impl. unwrapString ( from: keyValue, for: codingPathNode, _CodingKey? . none)
12131213
12141214 // Convert the snake case keys in the container to camel case.
12151215 // If we hit a duplicate key after conversion, then we'll use the first one we saw.
@@ -1219,8 +1219,8 @@ extension JSONDecoderImpl {
12191219 case . custom( let converter) :
12201220 let codingPathForCustomConverter = codingPathNode. path
12211221 while let ( keyValue, value) = iter. next ( ) {
1222- // Failing to unwrap a string here is impossible, as scanning already guarantees that dictionary keys are strings.
1223- let key = try ! impl. unwrapString ( from: keyValue, for: codingPathNode, _CodingKey? . none)
1222+ // We know these values are keys, but UTF-8 decoding could still fail.
1223+ let key = try impl. unwrapString ( from: keyValue, for: codingPathNode, _CodingKey? . none)
12241224
12251225 var pathForKey = codingPathForCustomConverter
12261226 pathForKey. append ( _CodingKey ( stringValue: key) !)
0 commit comments