[#3079] Fix config parsing for json objects

* If a curly brace was used in a string then find_json_ojects would
   fail to find objects correctly. To fix this ignore double-quoted entries.
This commit is contained in:
Calum Lind 2017-06-28 10:32:35 +01:00
parent 7b87a93862
commit 33e9545cd4
2 changed files with 23 additions and 1 deletions

View File

@ -91,8 +91,13 @@ def find_json_objects(s):
if start < 0: if start < 0:
return [] return []
quoted = False
for index, c in enumerate(s[offset:]): for index, c in enumerate(s[offset:]):
if c == '{': if c == '"':
quoted = not quoted
elif quoted:
continue
elif c == '{':
opens += 1 opens += 1
elif c == '}': elif c == '}':
opens -= 1 opens -= 1

View File

@ -168,3 +168,20 @@ class ConfigTestCase(unittest.TestCase):
objects = find_json_objects(s) objects = find_json_objects(s)
self.assertEqual(len(objects), 2) self.assertEqual(len(objects), 2)
def test_find_json_objects_curly_brace(self):
"""Test with string containing curly brace"""
s = """{
"file": 1,
"format": 1
}{
"ssl": true,
"enabled": false,
"port": 8115
"password": "abc{def"
}\n"""
from deluge.config import find_json_objects
objects = find_json_objects(s)
self.assertEqual(len(objects), 2)