From 36dd2440216c7ec7e00ccfefb187bfb1100a98a0 Mon Sep 17 00:00:00 2001 From: arturoeanton Date: Mon, 12 Jul 2021 23:13:37 -0300 Subject: [PATCH] Fix #368:Fix and add test, Lone quote in string isn't parsed correctly --- .vscode/settings.json | 12 ++++++++++++ tests/test_api.py | 7 +++++++ toml/decoder.py | 4 +--- 3 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..4bd07ef --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,12 @@ +{ + "python.testing.unittestArgs": [ + "-v", + "-s", + "./tests", + "-p", + "test_*.py" + ], + "python.testing.pytestEnabled": true, + "python.testing.nosetestsEnabled": false, + "python.testing.unittestEnabled": false +} \ No newline at end of file diff --git a/tests/test_api.py b/tests/test_api.py index 1acc26f..84dae75 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -16,6 +16,13 @@ TEST_DICT = {"a": {"b": 1, "c": 2}} +def test_bug_368(): + data = toml.loads(toml.dumps({"a": "\""})) + assert "\"" == data["a"] + +def test_bug_368Bis(): + data = toml.loads(toml.dumps({"a": ''})) + assert '' == data["a"] def test_bug_148(): assert 'a = "\\u0064"\n' == toml.dumps({'a': '\\x64'}) diff --git a/toml/decoder.py b/toml/decoder.py index bf400e9..0cb393f 100644 --- a/toml/decoder.py +++ b/toml/decoder.py @@ -872,9 +872,7 @@ def load_value(self, v, strictly_valid=True): v = _load_unicode_escapes(hexbytes[0], hexbytes[1:], prefix) v = _unescape(v) - if len(v) > 1 and v[1] == quotechar and (len(v) < 3 or - v[1] == v[2]): - v = v[2:-2] + return (v[1:-1], "str") elif v[0] == '[': return (self.load_array(v), "array")