diff --git a/include/toml++/impl/parser.inl b/include/toml++/impl/parser.inl index 89682f28..f9b03c8e 100644 --- a/include/toml++/impl/parser.inl +++ b/include/toml++/impl/parser.inl @@ -3157,6 +3157,11 @@ TOML_IMPL_NAMESPACE_START if (*cp == U']') set_error_and_return_default("tables with blank bare keys are explicitly prohibited"sv); + if (!is_bare_key_character(*cp) && !is_string_delimiter(*cp)) + set_error_and_return_default("expected bare key starting character or string delimiter, saw '"sv, + to_sv(*cp), + "'"sv); + // get the actual key start_recording(); parse_key(); diff --git a/tests/parsing_tables.cpp b/tests/parsing_tables.cpp index 417427e5..fa21bf2e 100644 --- a/tests/parsing_tables.cpp +++ b/tests/parsing_tables.cpp @@ -20,6 +20,11 @@ TEST_CASE("parsing - tables") }); parsing_should_fail(FILE_LINE_ARGS, "[]"sv); + parsing_should_fail(FILE_LINE_ARGS, "[[[1]]]"sv); + parsing_should_fail(FILE_LINE_ARGS, "[[[a]]]"sv); + parsing_should_fail(FILE_LINE_ARGS, "[[[]]"sv); + parsing_should_fail(FILE_LINE_ARGS, "[[="sv); + // "Under that, and until the next header or EOF, are the key/values of that table. // Key/value pairs within tables are not guaranteed to be in any specific order." parsing_should_succeed(FILE_LINE_ARGS, diff --git a/toml.hpp b/toml.hpp index 91f99d9f..fc12d078 100644 --- a/toml.hpp +++ b/toml.hpp @@ -15741,6 +15741,11 @@ TOML_IMPL_NAMESPACE_START if (*cp == U']') set_error_and_return_default("tables with blank bare keys are explicitly prohibited"sv); + if (!is_bare_key_character(*cp) && !is_string_delimiter(*cp)) + set_error_and_return_default("expected bare key starting character or string delimiter, saw '"sv, + to_sv(*cp), + "'"sv); + // get the actual key start_recording(); parse_key();