diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2015-04-17 18:05:45 -0700 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2015-04-17 18:05:45 -0700 |
commit | 846a93684d2d81ef102717004cd076c1b93544f7 (patch) | |
tree | 18615d57b3ae7d10f1a7ace71504226fde5d42ad /lib | |
parent | 5f9b3bd8e896cdba674d16dff83d4c9463d752d7 (diff) | |
download | ffi-yajl-846a93684d2d81ef102717004cd076c1b93544f7.tar.gz |
add :unique_key_checking flag to parserlcg/unique_key_checking
can be used to error out if keys are duplicated in input rather than
silently replacing.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ffi_yajl/ffi/parser.rb | 3 | ||||
-rw-r--r-- | lib/ffi_yajl/parser.rb | 2 |
2 files changed, 5 insertions, 0 deletions
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 == "" |