This repository has been archived by the owner. It is now read-only.

Fix for #2 #3

Open
wants to merge 1 commit into
from
Jump to file or symbol
Failed to load files and symbols.
+14 −0
Split
View
@@ -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];
View
@@ -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