Skip to content

Commit f704b0e

Browse files
committed
Check for : and / while updating nested dict structures in DottedDict
Fixes #1858
1 parent ed70eb2 commit f704b0e

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

plugin/core/collections.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def get_resolved(self, variables: Dict[str, str]) -> Dict[str, Any]:
154154
return sublime.expand_variables(self._d, variables)
155155

156156
def _update_recursive(self, current: Dict[str, Any], prefix: str) -> None:
157-
if not current:
157+
if not current or any(filter(lambda key: isinstance(key, str) and (":" in key or "/" in key), current.keys())):
158158
return self.set(prefix, current)
159159
for key, value in current.items():
160160
path = "{}.{}".format(prefix, key)

tests/test_collections.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,45 @@ def test_update_empty_dict(self) -> None:
137137
self.assertEqual(d.get(), {"a": {}})
138138
d.update({"a": {"b": {}}})
139139
self.assertEqual(d.get(), {"a": {"b": {}}})
140+
141+
def test_from_base_and_override(self) -> None:
142+
base = DottedDict({
143+
"yaml.schemas": {}
144+
})
145+
override = {
146+
"yaml.schemas": {
147+
"http://foo.com/bar.json": "**/*.json"
148+
}
149+
}
150+
result = DottedDict.from_base_and_override(base, override)
151+
self.assertEqual(
152+
result.get(None),
153+
{
154+
"yaml": {
155+
"schemas": {
156+
"http://foo.com/bar.json": "**/*.json"
157+
}
158+
}
159+
}
160+
)
161+
162+
def test_update_with_dicts(self) -> None:
163+
base = {
164+
"settings": {
165+
"yaml.schemas": {}
166+
}
167+
}
168+
overrides = {
169+
"yaml.schemas": {
170+
"http://foo.com/bar.json": "**/*.json"
171+
}
172+
}
173+
settings = DottedDict(base.get("settings", {}))
174+
settings.update(overrides)
175+
self.assertEqual(settings.get(), {
176+
"yaml": {
177+
"schemas": {
178+
"http://foo.com/bar.json": "**/*.json"
179+
}
180+
}
181+
})

0 commit comments

Comments
 (0)