diff --git a/tests/examples/table_names_with_string_delimiters.toml b/tests/examples/table_names_with_string_delimiters.toml new file mode 100644 index 00000000..8efd3efb --- /dev/null +++ b/tests/examples/table_names_with_string_delimiters.toml @@ -0,0 +1,5 @@ +['Special "table"'] +foo = "bar" + +["BJ's Restaurant"] +account = "dining" diff --git a/tests/test_api.py b/tests/test_api.py index 86b589b8..a19bddaf 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -53,6 +53,7 @@ def json_serial(obj): "newline_in_strings", "preserve_quotes_in_string", "string_slash_whitespace_newline", + "table_names_with_string_delimiters", ], ) def test_parse_can_parse_valid_toml_files(example, example_name): diff --git a/tomlkit/parser.py b/tomlkit/parser.py index ecb2a752..0ff26f09 100644 --- a/tomlkit/parser.py +++ b/tomlkit/parser.py @@ -219,7 +219,12 @@ def _split_table_name(self, name): # type: (str) -> Generator[Key] continue elif c in {"'", '"'}: if in_name: - if t == KeyType.Literal and c == '"': + if ( + t == KeyType.Literal + and c == '"' + or t == KeyType.Basic + and c == "'" + ): current += c continue