diff --git a/ext/date_performance.c b/ext/date_performance.c index ed2ce17..971b43f 100644 --- a/ext/date_performance.c +++ b/ext/date_performance.c @@ -301,6 +301,10 @@ rb_date_strptime(int argc, VALUE * argv, VALUE self) VALUE str = (argc > 0 ? argv[0] : rb_str_new2("-4712-01-01")), fmt = (argc > 1 ? argv[1] : DEFAULT_FORMAT), sg = (argc > 2 ? argv[2] : ITALY); + + Check_Type(str, T_STRING); + Check_Type(fmt, T_STRING); + char * ps = RSTRING(str)->ptr; char * pf = RSTRING(fmt)->ptr; VALUE parts[4]; diff --git a/test/extension_test.rb b/test/extension_test.rb index e7c2bdb..a6e9032 100644 --- a/test/extension_test.rb +++ b/test/extension_test.rb @@ -64,6 +64,16 @@ def test_sys_strptime assert_equal Date.new(1912, 6, 23), Date.sys_strptime("1912-06-23", "%Y-%m-%d") end + def test_strptime_str_input_handling + assert_raise(TypeError) { Date.strptime(19120623, '%Y%m%d') } + assert_raise(TypeError) { Date.strptime(nil, '%Y%m%d') } + end + + def test_strptime_fmt_input_handling + assert_raise(TypeError) { Date.strptime('19120623', 12345) } + assert_raise(TypeError) { Date.strptime('19120623', nil) } + end + # This falls back on Ruby's strptime on BSD systems because BSD's strptime doesn't # handle years before 1900. def test_strptime_fallback