Skip to content

Commit

Permalink
format-json: allow spaces around = in key=value expressions
Browse files Browse the repository at this point in the history
Signed-off-by: Hofi <hofione@gmail.com>
  • Loading branch information
HofiOne committed Aug 29, 2024
1 parent 90437d1 commit 138496e
Showing 1 changed file with 36 additions and 9 deletions.
45 changes: 36 additions & 9 deletions lib/template/compiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ log_template_compiler_process_arg_list(LogTemplateCompiler *self, GPtrArray *res
{
GString *arg_buf = g_string_sized_new(32);
gboolean arg_buf_has_a_value = FALSE;
gboolean kv_expr = FALSE;
gint parens = 1;
self->cursor++;

Expand Down Expand Up @@ -251,23 +252,44 @@ log_template_compiler_process_arg_list(LogTemplateCompiler *self, GPtrArray *res
else if (*self->cursor == '"' || *self->cursor == '\'')
{
if (!log_template_compiler_add_quoted_string(self, parens == 1, arg_buf))
{
g_ptr_array_add(result, NULL);
g_string_free(arg_buf, TRUE);
return FALSE;
}
goto exit_with_error;
arg_buf_has_a_value = TRUE;
kv_expr = FALSE;
continue;
}
else if (*self->cursor == '=')
{
if (kv_expr)
goto exit_with_error;
kv_expr = TRUE;
}
else if (parens == 1 && g_ascii_isspace(*self->cursor))
{
g_ptr_array_add(result, g_strndup(arg_buf->str, arg_buf->len));
g_string_truncate(arg_buf, 0);
arg_buf_has_a_value = FALSE;
while (*self->cursor && g_ascii_isspace(*self->cursor))
self->cursor++;
continue;
if (*self->cursor == '=' || kv_expr)
{
if (kv_expr)
{
if (*self->cursor == '=')
goto exit_with_error;
else
continue;
}
else
kv_expr = TRUE;
}
else
{
g_ptr_array_add(result, g_strndup(arg_buf->str, arg_buf->len));
g_string_truncate(arg_buf, 0);
arg_buf_has_a_value = FALSE;
kv_expr = FALSE;
continue;
}
}
else
kv_expr = FALSE;
log_template_compiler_append_and_increment(self, arg_buf);
arg_buf_has_a_value = TRUE;
}
Expand All @@ -278,6 +300,11 @@ log_template_compiler_process_arg_list(LogTemplateCompiler *self, GPtrArray *res
g_ptr_array_add(result, NULL);
g_string_free(arg_buf, TRUE);
return *self->cursor == ')';

exit_with_error:
g_ptr_array_add(result, NULL);
g_string_free(arg_buf, TRUE);
return FALSE;
}

static gboolean
Expand Down

0 comments on commit 138496e

Please sign in to comment.