Skip to content

Commit

Permalink
Raise exception on duplicate keys
Browse files Browse the repository at this point in the history
  • Loading branch information
getaaron authored and hsbt committed May 13, 2022
1 parent 40743b3 commit 469c7e3
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/psych/handlers/document_stream.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ def end_document implicit_end = !streaming?
@last.implicit_end = implicit_end
@block.call pop
end

def end_mapping
mapping = pop
keys = {}
mapping.children.each_slice(2) do |(key_scalar, _)|
next if key_scalar.is_a?(Psych::Nodes::Sequence) or key_scalar.is_a?(Psych::Nodes::Alias) or key_scalar.is_a?(Psych::Nodes::Mapping)
key = key_scalar.value
raise Psych::Exception, "Duplicate key #{key} exists on this level" if keys.key? key
keys[key] = nil
end
mapping
end
end
end
end

0 comments on commit 469c7e3

Please sign in to comment.