mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
Fix for JSON formatter
In the event that the first entry in a record is optional AND not present, the serializer will incorrectly add a leading comma. This leading common is invalid JSON and will, more often than not, cause parser failures downstream.
This commit is contained in:
parent
81d141959f
commit
295dbc3055
1 changed files with 8 additions and 2 deletions
|
@ -35,8 +35,14 @@ bool JSON::Describe(ODesc* desc, int num_fields, const Field* const * fields,
|
|||
const u_char* bytes = desc->Bytes();
|
||||
int len = desc->Len();
|
||||
|
||||
if ( i > 0 && len > 0 && bytes[len-1] != ',' && vals[i]->present )
|
||||
desc->AddRaw(",");
|
||||
if ( i > 0 && len > 0 && bytes[len-1] != ',' && vals[i]->present ) {
|
||||
// Issue if the first value of a record is optional AND not present
|
||||
// then an empty json field will be produced, which is invalid.
|
||||
// - ANE - 10/26/2015
|
||||
if (len > 1 && bytes[len-1] != '{') {
|
||||
desc->AddRaw(",");
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! Describe(desc, vals[i], fields[i]->name) )
|
||||
return false;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue