Skip to content

Commit

Permalink
Mimic parse error (#556)
Browse files Browse the repository at this point in the history
* Raise an exception on an invalid time represented as a decimal in  mode.

* Updated release info
  • Loading branch information
ohler55 authored Oct 1, 2019
1 parent b9af4b6 commit dbf7dec
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## 3.9.2 - 2019-10-01

- Fixed wrong exception type when mimicing the JSON gem.

## 3.9.1 - 2019-08-31

- Raise an exception on an invalid time represented as a decimal in `:object` mode.
Expand Down
4 changes: 4 additions & 0 deletions ext/oj/parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -1049,6 +1049,10 @@ oj_pi_parse(int argc, VALUE *argv, ParseInfo pi, char *json, size_t len, int yie
msg = rb_str_append(msg, oj_encode(rb_str_new2(pi->json)));
}
args[0] = msg;
if (pi->err.clas == oj_parse_error_class) {
// The error was an Oj::ParseError so change to a JSON::ParseError.
pi->err.clas = oj_json_parser_error_class;
}
rb_exc_raise(rb_class_new_instance(1, args, pi->err.clas));
} else {
oj_err_raise(&pi->err);
Expand Down
4 changes: 4 additions & 0 deletions ext/oj/sparse.c
Original file line number Diff line number Diff line change
Expand Up @@ -898,6 +898,10 @@ oj_pi_sparse(int argc, VALUE *argv, ParseInfo pi, int fd) {
// idea.
VALUE args[] = { oj_encode(rb_str_new2(pi->err.msg)) };

if (pi->err.clas == oj_parse_error_class) {
// The error was an Oj::ParseError so change to a JSON::ParseError.
pi->err.clas = oj_json_parser_error_class;
}
rb_exc_raise(rb_class_new_instance(1, args, pi->err.clas));
} else {
oj_err_raise(&pi->err);
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.9.1'
VERSION = '3.9.2'
end
5 changes: 2 additions & 3 deletions notes
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ Comparison Matrix
- encode_big_decimal_as_string
- add as fix for rails change


- rails

- Process::Status
- ActiveSupport::TimeWithZone
- ActiveModel::Errors
Expand All @@ -44,7 +43,7 @@ Comparison Matrix
- look at RUBY_PLATFORM maybe?
- look at env var for OJ_DEBUG when doing ruby extconf.rb
- add printf for keys spots in parse and dump

- invalid character option
- don't check options
- replace with best attempt such as \ud83d => \xED\xA0\xBD
Expand Down

0 comments on commit dbf7dec

Please sign in to comment.