Skip to content

Commit

Permalink
Raise an exception if EOF is reached and a string is unterminated
Browse files Browse the repository at this point in the history
  • Loading branch information
mraspberry committed Apr 22, 2020
1 parent f4f0b84 commit 5430910
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,3 +270,13 @@ def test_comment_preserve_decoder_encoder():
encoder=toml.TomlPreserveCommentEncoder())

assert len(s) == len(test_str) and sorted(test_str) == sorted(s)

@pytest.mark.parametrize('test_val', [
'opt = "unterminated double\n',
"opt = 'unterminated single\n",
"opt = '''\nunterminated\nraw multiline\n",
'opt = """\nunterminated\nmultiline\n',
])
def test_unterminated_string_eof(test_val):
with pytest.raises(toml.TomlDecodeError):
toml.loads(test_val)
3 changes: 3 additions & 0 deletions toml/decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,9 @@ def loads(s, _dict=dict, decoder=None):
if keyname:
raise TomlDecodeError("Key name found without value."
" Reached end of file.", original, len(s))
if openstring: # reached EOF and have an unterminated string
raise TomlDecodeError("Unterminated string found."
" Reached end of file.", original, len(s))
s = ''.join(sl)
s = s.split('\n')
multikey = None
Expand Down

0 comments on commit 5430910

Please sign in to comment.