Avoid whitespace around function type strings in JSON rendering

Callable types were rendered with a trailing "\n" in to_json() output. Tweaking
the Describe() calls to stop producing the newline is prone to test failures, so
this focuses on the JSON string production to suppress it, which doesn't affect
any tests.
This commit is contained in:
Christian Kreibich 2022-04-11 22:09:04 -07:00
parent fcef7f4925
commit 76ff976e83

View file

@ -420,8 +420,9 @@ static void BuildJSON(threading::formatter::JSON::NullDoubleWriter& writer, Val*
} }
rapidjson::Value j; rapidjson::Value j;
auto tag = val->GetType()->Tag();
switch ( val->GetType()->Tag() ) switch ( tag )
{ {
case TYPE_BOOL: case TYPE_BOOL:
writer.Bool(val->AsBool()); writer.Bool(val->AsBool());
@ -475,8 +476,15 @@ static void BuildJSON(threading::formatter::JSON::NullDoubleWriter& writer, Val*
ODesc d; ODesc d;
d.SetStyle(RAW_STYLE); d.SetStyle(RAW_STYLE);
val->Describe(&d); val->Describe(&d);
writer.String(util::json_escape_utf8( std::string desc(reinterpret_cast<const char*>(d.Bytes()), d.Len());
std::string(reinterpret_cast<const char*>(d.Bytes()), d.Len())));
// None of our function types should have surrounding
// whitespace, but ODesc might produce it due to its
// many output modes and flags. Strip it.
if ( tag == TYPE_FUNC )
desc = util::strstrip(desc);
writer.String(util::json_escape_utf8(desc));
break; break;
} }