cpprestsdk icon indicating copy to clipboard operation
cpprestsdk copied to clipboard

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

Open Wolftein opened this issue 3 years ago • 1 comments

OS: Ubuntu 20.04.2 Compiler: GCC 9.4.0

Example

{
    "user_id": 1,sasd123
    "post_id": 16
}

Wolftein avatar Mar 09 '22 03:03 Wolftein

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"));
     });
}

MS-Renan avatar Sep 06 '24 18:09 MS-Renan