microsoft / cpprestsdk

The C++ REST SDK is a Microsoft project for cloud-based client-server communication in native code using a modern asynchronous C++ API design. This project aims to help C++ developers connect to and interact with services.
Other
7.96k stars 1.65k forks source link

http_request::extract_json() crashes if malformed JSON is provided. #1691

Open Wolftein opened 2 years ago

Wolftein commented 2 years ago

OS: Ubuntu 20.04.2 Compiler: GCC 9.4.0

Example

{
    "user_id": 1,sasd123
    "post_id": 16
}
MS-Renan commented 1 day ago

I also had this issue and came across this

void handle_post(http_request request) {
      request.extract_json().then([request](pplx::task<web::json::value> task) {
        try {
          auto body = task.get();                    // Exception occurs
          ...
        } catch (const std::exception& e) {
          ucout << e.what() << std::endl;            // Example: Line 1, Column 3 Syntax error: Malformed token
          ...
        }
        request.reply(status_codes::OK, U("OK"));
     });
}