From 36dd2440216c7ec7e00ccfefb187bfb1100a98a0 Mon Sep 17 00:00:00 2001 From: arturoeanton Date: Mon, 12 Jul 2021 23:13:37 -0300 Subject: [PATCH 1/3] 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") From fbc15f2f31daf2282a70e64a2a98929be8a5e2eb Mon Sep 17 00:00:00 2001 From: arturoeanton Date: Mon, 12 Jul 2021 23:17:50 -0300 Subject: [PATCH 2/3] remove vscode --- .gitignore | 2 ++ .vscode/settings.json | 12 ------------ 2 files changed, 2 insertions(+), 12 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.gitignore b/.gitignore index 9f0b57d..d384825 100644 --- a/.gitignore +++ b/.gitignore @@ -112,3 +112,5 @@ venv.bak/ auto-save-list tramp .\#* + + diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 4bd07ef..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "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 From 7c82e35fba9e9853d6626fba04bdcaaf10a0f5dd Mon Sep 17 00:00:00 2001 From: arturoeanton Date: Mon, 12 Jul 2021 23:20:14 -0300 Subject: [PATCH 3/3] update gitignore with vscode --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index d384825..a4f2227 100644 --- a/.gitignore +++ b/.gitignore @@ -113,4 +113,5 @@ auto-save-list tramp .\#* - +# VScode +.vscode