Skip to content

Commit ffe5319

Browse files
authored
Merge pull request #141 from sstroemer/master
Detect duplicate keys of mapping nodes
2 parents 73f14e6 + e22a17b commit ffe5319

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

Project.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
name = "YAML"
22
uuid = "ddb6d928-2868-570f-bddf-ab3f9cf99eb6"
3-
version = "0.4.12"
3+
version = "0.4.13"
4+
45

56
[deps]
67
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"

src/constructor.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ function flatten_mapping(node::MappingNode)
175175
end
176176

177177

178-
function construct_mapping(dicttype::Union{Type,Function}, constructor::Constructor, node::MappingNode)
178+
function construct_mapping(dicttype::Union{Type,Function}, constructor::Constructor, node::MappingNode; strict_unique_keys::Bool=false)
179179
flatten_mapping(node)
180180
mapping = dicttype()
181181
for (key_node, value_node) in node.value
@@ -191,6 +191,9 @@ function construct_mapping(dicttype::Union{Type,Function}, constructor::Construc
191191
end
192192
end
193193
try
194+
if haskey(mapping, key)
195+
strict_unique_keys ? error("Duplicate key `$(key)` detected in mapping.") : @error "Duplicate key detected in mapping" node key
196+
end
194197
mapping[key] = value
195198
catch
196199
throw(ConstructorError(nothing, nothing,

0 commit comments

Comments
 (0)