@@ -1092,6 +1092,7 @@ std::unique_ptr<web::json::details::_Object> JSON_Parser<CharType>::_ParseObject
1092
1092
return obj;
1093
1093
1094
1094
error:
1095
+ parseStatus.didSucceed = false ;
1095
1096
parseStatus.errorMsg = _XPLATSTR (" Malformed object literal" );
1096
1097
return nullptr ;
1097
1098
@@ -1102,10 +1103,10 @@ std::unique_ptr<web::json::details::_Object> JSON_Parser<CharType>::_ParseObject
1102
1103
template <typename CharType>
1103
1104
std::unique_ptr<web::json::details::_Array> JSON_Parser<CharType>::_ParseArray(typename JSON_Parser<CharType>::Token &tkn, JsonParseStatus& parseStatus)
1104
1105
{
1105
- JsonParseStatus parseAttempt = GetNextToken (tkn);
1106
- if (!parseAttempt .didSucceed )
1106
+ parseStatus = GetNextToken (tkn);
1107
+ if (!parseStatus .didSucceed )
1107
1108
{
1108
- CreateError (tkn, parseAttempt. errorMsg ) ;
1109
+ return nullptr ;
1109
1110
}
1110
1111
1111
1112
auto result = utility::details::make_unique<web::json::details::_Array>();
@@ -1116,35 +1117,38 @@ std::unique_ptr<web::json::details::_Array> JSON_Parser<CharType>::_ParseArray(t
1116
1117
{
1117
1118
// State 1: Looking for an expression.
1118
1119
auto value = ParseValue (tkn, parseStatus);
1119
- if (!parseAttempt .didSucceed ) goto getNextTokenError;
1120
+ if (!parseStatus .didSucceed ) goto getNextTokenError;
1120
1121
1121
1122
result->m_array .m_elements .emplace_back (value);
1122
1123
1123
1124
// State 4: Looking for a comma or a closing bracket
1124
1125
switch (tkn.kind )
1125
1126
{
1126
1127
case JSON_Parser<CharType>::Token::TKN_Comma:
1127
- parseAttempt = GetNextToken (tkn);
1128
- if (!parseAttempt .didSucceed ) goto getNextTokenError;
1128
+ parseStatus = GetNextToken (tkn);
1129
+ if (!parseStatus .didSucceed ) goto getNextTokenError;
1129
1130
break ;
1130
1131
case JSON_Parser<CharType>::Token::TKN_CloseBracket:
1131
- parseAttempt = GetNextToken (tkn);
1132
- if (!parseAttempt .didSucceed ) goto getNextTokenError;
1132
+ parseStatus = GetNextToken (tkn);
1133
+ if (!parseStatus .didSucceed ) goto getNextTokenError;
1133
1134
1134
1135
return result;
1135
1136
default :
1136
- CreateError (tkn, _XPLATSTR (" Malformed array literal" ));
1137
+ parseStatus.didSucceed = false ;
1138
+ parseStatus.errorMsg = _XPLATSTR (" Malformed array literal" );
1139
+
1140
+ return nullptr ;
1137
1141
}
1138
1142
}
1139
1143
}
1140
1144
1141
- parseAttempt = GetNextToken (tkn);
1142
- if (!parseAttempt .didSucceed ) goto getNextTokenError;
1145
+ parseStatus = GetNextToken (tkn);
1146
+ if (!parseStatus .didSucceed ) goto getNextTokenError;
1143
1147
1144
1148
return result;
1145
1149
1146
1150
getNextTokenError:
1147
- CreateError (tkn, parseAttempt. errorMsg ) ;
1151
+ return nullptr ;
1148
1152
}
1149
1153
1150
1154
template <typename CharType>
@@ -1298,18 +1302,25 @@ web::json::value web::json::value::parse(const utility::string_t& str, std::erro
1298
1302
web::json::details::JSON_StringParser<utility::char_t > parser (str);
1299
1303
1300
1304
web::json::details::JSON_Parser<utility::char_t >::Token tkn;
1301
- auto parseAttempt = parser.GetNextToken (tkn);
1305
+ auto parseStatus = parser.GetNextToken (tkn);
1302
1306
web::json::value returnObject;
1303
1307
1304
- if (parseAttempt .didSucceed )
1308
+ if (parseStatus .didSucceed )
1305
1309
{
1306
- returnObject = parser.ParseValue (tkn, parseAttempt);
1310
+ returnObject = parser.ParseValue (tkn, parseStatus);
1311
+
1312
+ if (!parseStatus.didSucceed || tkn.kind != web::json::details::JSON_Parser<utility::char_t >::Token::TKN_EOF)
1313
+ {
1314
+ returnObject = web::json::value::null ();
1315
+ error = std::make_error_code (std::errc::protocol_error);
1316
+ }
1307
1317
}
1308
1318
else
1309
1319
{
1310
1320
returnObject = web::json::value::null ();
1311
1321
error = std::make_error_code (std::errc::protocol_error);
1312
1322
}
1323
+
1313
1324
return returnObject;
1314
1325
}
1315
1326
0 commit comments