Created
August 26, 2019 20:03
-
-
Save marvingreenberg/ba2f67f740400f722680fc7c538e94a0 to your computer and use it in GitHub Desktop.
pyyaml duplicate keys patch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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