Skip to content

Commit 99ce774

Browse files
authored
Merge pull request #286 from uptickmetachu/replace-deep-merge
fix: Removed CC-BY-SA 3.0 non compliant implementation of dict_deep_merge
2 parents edb8d5e + e2e1bc4 commit 99ce774

File tree

1 file changed

+10
-18
lines changed

1 file changed

+10
-18
lines changed

src/onelogin/saml2/idp_metadata_parser.py

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -252,22 +252,14 @@ def merge_settings(settings, new_metadata_settings):
252252
return result_settings
253253

254254

255-
def dict_deep_merge(a, b, path=None):
256-
"""Deep-merge dictionary `b` into dictionary `a`.
257-
Kudos to http://stackoverflow.com/a/7205107/145400
258-
"""
259-
if path is None:
260-
path = []
261-
for key in b:
262-
if key in a:
263-
if isinstance(a[key], dict) and isinstance(b[key], dict):
264-
dict_deep_merge(a[key], b[key], path + [str(key)])
265-
elif a[key] == b[key]:
266-
# Key conflict, but equal value.
267-
pass
268-
else:
269-
# Key/value conflict. Prioritize b over a.
270-
a[key] = b[key]
255+
def dict_deep_merge(lhs, rhs):
256+
"""Deep-merge dictionary `rhs` into dictionary `lhs`."""
257+
updated_rhs = {}
258+
for key in rhs:
259+
if key in lhs and isinstance(lhs[key], dict) and isinstance(rhs[key], dict):
260+
updated_rhs[key] = dict_deep_merge(lhs[key], rhs[key])
271261
else:
272-
a[key] = b[key]
273-
return a
262+
updated_rhs[key] = rhs[key]
263+
lhs.update(updated_rhs)
264+
return lhs
265+

0 commit comments

Comments
 (0)