mirror of
https://github.com/codex-storage/deluge.git
synced 2025-02-04 23:53:23 +00:00
[#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:
parent
7b87a93862
commit
33e9545cd4
@ -91,8 +91,13 @@ def find_json_objects(s):
|
||||
if start < 0:
|
||||
return []
|
||||
|
||||
quoted = False
|
||||
for index, c in enumerate(s[offset:]):
|
||||
if c == '{':
|
||||
if c == '"':
|
||||
quoted = not quoted
|
||||
elif quoted:
|
||||
continue
|
||||
elif c == '{':
|
||||
opens += 1
|
||||
elif c == '}':
|
||||
opens -= 1
|
||||
|
@ -168,3 +168,20 @@ class ConfigTestCase(unittest.TestCase):
|
||||
|
||||
objects = find_json_objects(s)
|
||||
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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user