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
4 changes: 2 additions & 2 deletions ext/date/date_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ static VALUE eDateError;
static VALUE half_days_in_day, day_in_nanoseconds;
static double positive_inf, negative_inf;

// used by deconstruct_keys
/* used by deconstruct_keys */
static VALUE sym_year, sym_month, sym_day, sym_yday, sym_wday;
static VALUE sym_hour, sym_min, sym_sec, sym_sec_fraction, sym_zone;

Expand Down Expand Up @@ -4528,6 +4528,7 @@ date_s__strptime_internal(int argc, VALUE *argv, VALUE klass,
rb_scan_args(argc, argv, "11", &vstr, &vfmt);

StringValue(vstr);
if (argc > 1) StringValue(vfmt);
if (!rb_enc_str_asciicompat_p(vstr))
rb_raise(rb_eArgError,
"string should have ASCII compatible encoding");
Expand All @@ -4538,7 +4539,6 @@ date_s__strptime_internal(int argc, VALUE *argv, VALUE klass,
flen = strlen(default_fmt);
}
else {
StringValue(vfmt);
if (!rb_enc_str_asciicompat_p(vfmt))
rb_raise(rb_eArgError,
"format should have ASCII compatible encoding");
Expand Down
6 changes: 3 additions & 3 deletions ext/date/date_strptime.c
Original file line number Diff line number Diff line change
Expand Up @@ -661,16 +661,16 @@ date__strptime(const char *str, size_t slen,

si = date__strptime_internal(str, slen, fmt, flen, hash);

if (fail_p())
return Qnil;

if (slen > si) {
VALUE s;

s = rb_usascii_str_new(&str[si], slen - si);
set_hash("leftover", s);
}

if (fail_p())
return Qnil;

cent = del_hash("_cent");
if (!NIL_P(cent)) {
VALUE year;
Expand Down
15 changes: 14 additions & 1 deletion test/date/test_date_strptime.rb
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,20 @@ def test_sz
d = DateTime.strptime('9000 +0200', '%Q %z')
assert_equal([1970, 1, 1, 2, 0, 9], [d.year, d.mon, d.mday, d.hour, d.min, d.sec])
assert_equal(Rational(2, 24), d.offset)

end

def test_format_modified
str = " " * 100
fmt = Struct.new(:str) {
def to_str
str << "2026-06-01" << " "*100
" %F "
end
}.new(str)
d = Date._strptime(str, fmt)
assert_not_nil(d)
assert_equal(2026, d[:year])
assert_equal(6, d[:mon])
assert_equal(1, d[:mday])
end
end
Loading