mirror of
https://gitee.com/zyjblog/oatpp.git
synced 2024-12-22 22:16:37 +08:00
Merge pull request #904 from linhaojun857/fix_902
Fix the bug of send "null" in request body causes seg-fault
This commit is contained in:
commit
a5fe65becc
@ -126,7 +126,7 @@ public:
|
||||
auto type = Wrapper::Class::getType();
|
||||
oatpp::parser::Caret caret(str);
|
||||
auto result = read(caret, type).template cast<Wrapper>();
|
||||
if(result == nullptr) {
|
||||
if(caret.hasError()) {
|
||||
throw oatpp::parser::ParsingError(caret.getErrorMessage(), caret.getErrorCode(), caret.getPosition());
|
||||
}
|
||||
return result;
|
||||
|
@ -341,6 +341,46 @@ void FullTest::onRun() {
|
||||
OATPP_ASSERT(returnedData == data)
|
||||
}
|
||||
|
||||
{
|
||||
String bodyIn = "null";
|
||||
auto response = client->testBodyIsNull1(bodyIn, connection);
|
||||
OATPP_ASSERT(response->getStatusCode() == 400)
|
||||
auto returnedData = response->readBodyToString();
|
||||
OATPP_ASSERT(returnedData)
|
||||
OATPP_ASSERT(returnedData == "server=oatpp/" OATPP_VERSION "\n"
|
||||
"code=400\n"
|
||||
"description=Bad Request\n"
|
||||
"message=Missing valid body parameter 'body'\n")
|
||||
connection = client->getConnection();
|
||||
}
|
||||
|
||||
{
|
||||
String bodyIn = "\"null\"";
|
||||
auto response = client->testBodyIsNull1(bodyIn, connection);
|
||||
OATPP_ASSERT(response->getStatusCode() == 200)
|
||||
auto returnedData = response->readBodyToString();
|
||||
OATPP_ASSERT(returnedData)
|
||||
OATPP_ASSERT(returnedData == "OK---null")
|
||||
}
|
||||
|
||||
{
|
||||
String bodyIn = "null";
|
||||
auto response = client->testBodyIsNull2(bodyIn, connection);
|
||||
OATPP_ASSERT(response->getStatusCode() == 200)
|
||||
auto returnedData = response->readBodyToString();
|
||||
OATPP_ASSERT(returnedData)
|
||||
OATPP_ASSERT(returnedData == "OK---null")
|
||||
}
|
||||
|
||||
{
|
||||
String bodyIn = "\"null\"";
|
||||
auto response = client->testBodyIsNull2(bodyIn, connection);
|
||||
OATPP_ASSERT(response->getStatusCode() == 200)
|
||||
auto returnedData = response->readBodyToString();
|
||||
OATPP_ASSERT(returnedData)
|
||||
OATPP_ASSERT(returnedData == "OK---\"null\"")
|
||||
}
|
||||
|
||||
{
|
||||
auto response = client->headerValueSet(" VALUE_1, VALUE_2, VALUE_3", connection);
|
||||
OATPP_ASSERT(response->getStatusCode() == 200)
|
||||
|
@ -62,6 +62,8 @@ public:
|
||||
API_CALL("GET", "enum/as-number", getHeaderEnumAsNumber, HEADER(Enum<AllowedPathParams>::AsNumber, enumValue, "enum"))
|
||||
|
||||
API_CALL("POST", "echo", echoBody, BODY_STRING(String, body))
|
||||
API_CALL("POST", "testBodyIsNull1", testBodyIsNull1, BODY_STRING(String, body))
|
||||
API_CALL("POST", "testBodyIsNull2", testBodyIsNull2, BODY_STRING(String, body))
|
||||
API_CALL("GET", "header-value-set", headerValueSet, HEADER(String, valueSet, "X-VALUE-SET"))
|
||||
|
||||
API_CALL("GET", "default-basic-authorization", defaultBasicAuthorization, AUTHORIZATION_BASIC(String, authString))
|
||||
|
@ -163,6 +163,16 @@ public:
|
||||
return createResponse(Status::CODE_200, body);
|
||||
}
|
||||
|
||||
ENDPOINT("POST", "testBodyIsNull1", testBodyIsNull1,
|
||||
BODY_DTO(String, body)) {
|
||||
return createResponse(Status::CODE_200, "OK---" + body);
|
||||
}
|
||||
|
||||
ENDPOINT("POST", "testBodyIsNull2", testBodyIsNull2,
|
||||
BODY_STRING(String, body)) {
|
||||
return createResponse(Status::CODE_200, "OK---" + body);
|
||||
}
|
||||
|
||||
ENDPOINT("GET", "header-value-set", headerValueSet,
|
||||
HEADER(String, valueSet, "X-VALUE-SET")) {
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user