Skip to content

Commit

Permalink
Mimic json gem allowing nil second arg to parse
Browse files Browse the repository at this point in the history
  • Loading branch information
ohler55 committed Aug 1, 2017
1 parent 8da0354 commit 21ea259
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 21 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# CHANGELOG

## 3.3.3 - 2017-08-01

- Allow nil as a second argument to parse when mimicking the json gem. This is
a special case where the gem does not raise an exception on a non-Hash
second argument.

## 3.3.2 - 2017-07-11

- Fixed Windows compile issue regarding timegm().
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# https://www.appveyor.com/docs/lang/ruby/

version: 3.0.{build}-{branch}
version: 3.3.2-{build}-{branch}

image: Visual Studio 2015

Expand Down
4 changes: 3 additions & 1 deletion ext/oj/mimic_json.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ oj_parse_mimic_dump_options(VALUE ropts, Options copts) {
ropts = rb_funcall(ropts, oj_to_hash_id, 0);
} else if (rb_respond_to(ropts, oj_to_h_id)) {
ropts = rb_funcall(ropts, oj_to_h_id, 0);
} else if (Qnil == ropts) {
return;
} else {
rb_raise(rb_eArgError, "options must be a hash.");
}
Expand Down Expand Up @@ -505,7 +507,7 @@ mimic_parse_core(int argc, VALUE *argv, VALUE self, bool bang) {
pi.options.mode = CompatMode;
pi.max_depth = 100;

if (2 <= argc) {
if (2 <= argc && Qnil != argv[1]) {
VALUE ropts = argv[1];
VALUE v;

Expand Down
38 changes: 20 additions & 18 deletions ext/oj/oj.c
Original file line number Diff line number Diff line change
Expand Up @@ -749,24 +749,26 @@ load(int argc, VALUE *argv, VALUE self) {
VALUE ropts = argv[1];
VALUE v;

Check_Type(ropts, T_HASH);
if (Qnil != (v = rb_hash_lookup(ropts, mode_sym))) {
if (object_sym == v) {
mode = ObjectMode;
} else if (strict_sym == v) {
mode = StrictMode;
} else if (compat_sym == v || json_sym == v) {
mode = CompatMode;
} else if (null_sym == v) {
mode = NullMode;
} else if (custom_sym == v) {
mode = CustomMode;
} else if (rails_sym == v) {
mode = RailsMode;
} else if (wab_sym == v) {
mode = WabMode;
} else {
rb_raise(rb_eArgError, ":mode must be :object, :strict, :compat, :null, :custom, :rails, or :wab.");
if (Qnil != ropts || CompatMode != mode) {
Check_Type(ropts, T_HASH);
if (Qnil != (v = rb_hash_lookup(ropts, mode_sym))) {
if (object_sym == v) {
mode = ObjectMode;
} else if (strict_sym == v) {
mode = StrictMode;
} else if (compat_sym == v || json_sym == v) {
mode = CompatMode;
} else if (null_sym == v) {
mode = NullMode;
} else if (custom_sym == v) {
mode = CustomMode;
} else if (rails_sym == v) {
mode = RailsMode;
} else if (wab_sym == v) {
mode = WabMode;
} else {
rb_raise(rb_eArgError, ":mode must be :object, :strict, :compat, :null, :custom, :rails, or :wab.");
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/oj/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

module Oj
# Current version of the module.
VERSION = '3.3.2'
VERSION = '3.3.3'
end

0 comments on commit 21ea259

Please sign in to comment.