Serialize integer-ish config keys properly
All checks were successful
Alpine 3.20 Success

This commit is contained in:
Přemysl Eric Janouch 2024-12-16 09:09:03 +01:00
parent 149938cc44
commit 32cbb15266
Signed by: p
GPG Key ID: A0420B94F92B9493
2 changed files with 5 additions and 3 deletions

View File

@ -4833,7 +4833,8 @@ config_item_write_kv_pair (struct config_writer *self,
str_append_printf (self->output, str_append_printf (self->output,
"%s# %s\n", indent, value->schema->comment); "%s# %s\n", indent, value->schema->comment);
bool can_use_word = true; char *end = NULL;
bool can_use_word = ((void) strtoll (key, &end, 10), end == key);
for (const char *p = key; *p; p++) for (const char *p = key; *p; p++)
if (!config_tokenizer_is_word_char (*p)) if (!config_tokenizer_is_word_char (*p))
can_use_word = false; can_use_word = false;

View File

@ -647,7 +647,7 @@ static const struct config_schema g_config_test[] =
.type = CONFIG_ITEM_INTEGER, .type = CONFIG_ITEM_INTEGER,
.validate = test_config_validate_nonnegative, .validate = test_config_validate_nonnegative,
.default_ = "1" }, .default_ = "1" },
{ .name = "foobar", { .name = "123",
.type = CONFIG_ITEM_STRING, .type = CONFIG_ITEM_STRING,
.default_ = "\"qux\\x01`\" \"\"`a`" }, .default_ = "\"qux\\x01`\" \"\"`a`" },
{} {}
@ -676,10 +676,11 @@ test_config (void)
config_item_destroy (invalid); config_item_destroy (invalid);
hard_assert (!strcmp ("qux\001`a", hard_assert (!strcmp ("qux\001`a",
config_item_get (config.root, "top.foobar", NULL)->value.string.str)); config_item_get (config.root, "top.123", NULL)->value.string.str));
struct str s = str_make (); struct str s = str_make ();
config_item_write (config.root, true, &s); config_item_write (config.root, true, &s);
print_debug ("%s", s.str);
struct config_item *parsed = config_item_parse (s.str, s.len, false, NULL); struct config_item *parsed = config_item_parse (s.str, s.len, false, NULL);
hard_assert (parsed); hard_assert (parsed);
config_item_destroy (parsed); config_item_destroy (parsed);