Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parse errors when single quotes are present in a table name #71

Merged
merged 1 commit into from
Feb 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions tests/examples/table_names_with_string_delimiters.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
['Special "table"']
foo = "bar"

["BJ's Restaurant"]
account = "dining"
1 change: 1 addition & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
7 changes: 6 additions & 1 deletion tomlkit/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down