diff --git a/tests/test_api.py b/tests/test_api.py index 3623662..2357537 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -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) diff --git a/toml/decoder.py b/toml/decoder.py index a24c04a..da7ea85 100644 --- a/toml/decoder.py +++ b/toml/decoder.py @@ -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