diff --git a/lib/psych/handlers/document_stream.rb b/lib/psych/handlers/document_stream.rb index b77115d0..bf555ebf 100644 --- a/lib/psych/handlers/document_stream.rb +++ b/lib/psych/handlers/document_stream.rb @@ -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