I have stumbled upon what looks like a bug in json::value::parse...
I was trying to parse a JSON object, which was returned by HTTP GET:
If I trim it down to bytesRead, everything works fine and parse succeeds.
But shouldn't it disregards trailing '\0'?
This problem can be reproduced in non_default_locale test (one of only two places in JSON tests suite, where json::value::parse is invoked!) by replacing
Also, how should one specify the maximum number of characters to read in concurrency::streams::istream::read to avoid the trailing '\0' in the result?
Thanks,
Boris
I was trying to parse a JSON object, which was returned by HTTP GET:
concurrency::streams::istream bodyStream = response.body();
concurrency::streams::container_buffer<std::string> inStringBuffer;
auto readTask = bodyStream.read(inStringBuffer, 100) // 100 is too much!
.then([](size_t bytesRead)
{
std::string responseBody = inStringBuffer.collection();
// responseBody.resize(bytesRead); // <--- uncomment this to prevent parse error
const utility::string_t responseUStr = utility::conversions::to_string_t(responseBody);
web::json::value json = web::json::value::parse(responseUStr);
parse failed because responseBody contained a bunch of trailing '\0' characters.If I trim it down to bytesRead, everything works fine and parse succeeds.
But shouldn't it disregards trailing '\0'?
This problem can be reproduced in non_default_locale test (one of only two places in JSON tests suite, where json::value::parse is invoked!) by replacing
utility::string_t str(U("[true,false,-1.55,5,null,{\"abc\":5555}]"));
with std::string s("[true,false,-1.55,5,null,{\"abc\":5555}]");
s.resize(s.length()+2, '\0'); // comment this line and the test succeeds
utility::string_t str = utility::conversions::to_string_t(s);
Is this a bug in web::json::value::parse or in utility::conversions::to_string_t?Also, how should one specify the maximum number of characters to read in concurrency::streams::istream::read to avoid the trailing '\0' in the result?
Thanks,
Boris