Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save marvingreenberg/ba2f67f740400f722680fc7c538e94a0 to your computer and use it in GitHub Desktop.
Save marvingreenberg/ba2f67f740400f722680fc7c538e94a0 to your computer and use it in GitHub Desktop.
pyyaml duplicate keys patch
diff --git a/lib/yaml/constructor.py b/lib/yaml/constructor.py
index 516dad1..598963c 100644
--- a/lib/yaml/constructor.py
+++ b/lib/yaml/constructor.py
@@ -136,6 +136,9 @@ class BaseConstructor(object):
except TypeError, exc:
raise ConstructorError("while constructing a mapping", node.start_mark,
"found unacceptable key (%s)" % exc, key_node.start_mark)
+ if key in mapping:
+ raise ConstructorError("while constructing a mapping", node.start_mark,
+ "found duplicate key (%s)" % key, key_node.start_mark)
value = self.construct_object(value_node, deep=deep)
mapping[key] = value
return mapping
diff --git a/lib3/yaml/constructor.py b/lib3/yaml/constructor.py
index 34fc1ae..8ab6b36 100644
--- a/lib3/yaml/constructor.py
+++ b/lib3/yaml/constructor.py
@@ -132,6 +132,9 @@ class BaseConstructor:
if not isinstance(key, collections.abc.Hashable):
raise ConstructorError("while constructing a mapping", node.start_mark,
"found unhashable key", key_node.start_mark)
+ if key in mapping:
+ raise ConstructorError("while constructing a mapping", node.start_mark,
+ "found duplicate key (%s)" % key, key_node.start_mark)
value = self.construct_object(value_node, deep=deep)
mapping[key] = value
return mapping
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment