From 846a93684d2d81ef102717004cd076c1b93544f7 Mon Sep 17 00:00:00 2001 From: Lamont Granquist Date: Fri, 17 Apr 2015 18:05:45 -0700 Subject: add :unique_key_checking flag to parser can be used to error out if keys are duplicated in input rather than silently replacing. --- lib/ffi_yajl/ffi/parser.rb | 3 +++ lib/ffi_yajl/parser.rb | 2 ++ 2 files changed, 5 insertions(+) (limited to 'lib') diff --git a/lib/ffi_yajl/ffi/parser.rb b/lib/ffi_yajl/ffi/parser.rb index b97b2de..8e4dc07 100644 --- a/lib/ffi_yajl/ffi/parser.rb +++ b/lib/ffi_yajl/ffi/parser.rb @@ -30,6 +30,9 @@ module FFI_Yajl case stack.last when Hash raise FFI_Yajl::ParseError.new("internal error: missing key in parse") if key.nil? + if @opts[:unique_key_checking] && stack.last.has_key?(key) + raise FFI_Yajl::ParseError.new("repeated key: #{key}") + end stack.last[key] = val when Array stack.last.push(val) diff --git a/lib/ffi_yajl/parser.rb b/lib/ffi_yajl/parser.rb index d8389d7..5b9a0c9 100644 --- a/lib/ffi_yajl/parser.rb +++ b/lib/ffi_yajl/parser.rb @@ -75,6 +75,8 @@ module FFI_Yajl yajl_opts[:yajl_allow_multiple_values] = @opts[:allow_multiple_values] yajl_opts[:yajl_allow_partial_values] = @opts[:allow_partial_values] + yajl_opts[:unique_key_checking] = @opts[:unique_key_checking] + # XXX: bug-compat with ruby-yajl return nil if str == "" -- cgit v1.2.1