mirror of
https://github.com/zeek/zeek.git
synced 2025-10-07 09:08:20 +00:00
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:
parent
fcef7f4925
commit
76ff976e83
1 changed files with 11 additions and 3 deletions
14
src/Val.cc
14
src/Val.cc
|
@ -420,8 +420,9 @@ static void BuildJSON(threading::formatter::JSON::NullDoubleWriter& writer, Val*
|
|||
}
|
||||
|
||||
rapidjson::Value j;
|
||||
auto tag = val->GetType()->Tag();
|
||||
|
||||
switch ( val->GetType()->Tag() )
|
||||
switch ( tag )
|
||||
{
|
||||
case TYPE_BOOL:
|
||||
writer.Bool(val->AsBool());
|
||||
|
@ -475,8 +476,15 @@ static void BuildJSON(threading::formatter::JSON::NullDoubleWriter& writer, Val*
|
|||
ODesc d;
|
||||
d.SetStyle(RAW_STYLE);
|
||||
val->Describe(&d);
|
||||
writer.String(util::json_escape_utf8(
|
||||
std::string(reinterpret_cast<const char*>(d.Bytes()), d.Len())));
|
||||
std::string desc(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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue