Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ext/bigdecimal/bigdecimal.c
Original file line number Diff line number Diff line change
Expand Up @@ -2845,6 +2845,7 @@ rb_cstr_convert_to_BigDecimal(const char *c_str, int raise_exception)
static inline VALUE
rb_str_convert_to_BigDecimal(VALUE val, int raise_exception)
{
if (!raise_exception && memchr(RSTRING_PTR(val), '\0', RSTRING_LEN(val))) return Qnil;
const char *c_str = StringValueCStr(val);
return rb_cstr_convert_to_BigDecimal(c_str, raise_exception);
}
Expand Down
6 changes: 6 additions & 0 deletions test/bigdecimal/test_bigdecimal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,12 @@ def test_BigDecimal_with_exception_keyword
assert_nothing_raised(ArgumentError) {
assert_equal(nil, BigDecimal(".", exception: false))
}
assert_raise(ArgumentError) {
BigDecimal("1\0", exception: true)
}
assert_nothing_raised(ArgumentError) {
assert_equal(nil, BigDecimal("1\0", exception: false))
}
assert_raise(ArgumentError) {
BigDecimal("1", -1, exception: true)
}
Expand Down