Skip to content
Open
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
30 changes: 21 additions & 9 deletions ext/date/date_parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -2590,7 +2590,11 @@ date__iso8601(VALUE str)
}

#undef SNUM
#define SNUM 8
#define SNUM 9

#ifndef HAVE_RB_CATEGORY_WARN
#define rb_category_warn(category, fmt) rb_warn(fmt)
#endif

static int
rfc3339_cb(VALUE m, VALUE hash)
Expand All @@ -2604,16 +2608,24 @@ rfc3339_cb(VALUE m, VALUE hash)
s[i] = rb_reg_nth_match(i, m);
}

{
int c = RSTRING_PTR(s[4])[0];
if (c != 't' && c != 'T' && c != ' ')
rb_category_warn(RB_WARN_CATEGORY_DEPRECATED,
"Invalid RFC3339 date time separator provided, "
"this will raise an error in a future version.");
}

set_hash("year", str2num(s[1]));
set_hash("mon", str2num(s[2]));
set_hash("mday", str2num(s[3]));
set_hash("hour", str2num(s[4]));
set_hash("min", str2num(s[5]));
set_hash("sec", str2num(s[6]));
set_hash("zone", s[8]);
set_hash("offset", date_zone_to_diff(s[8]));
if (!NIL_P(s[7]))
set_hash("sec_fraction", sec_fraction(s[7]));
set_hash("hour", str2num(s[5]));
set_hash("min", str2num(s[6]));
set_hash("sec", str2num(s[7]));
set_hash("zone", s[9]);
set_hash("offset", date_zone_to_diff(s[9]));
if (!NIL_P(s[8]))
set_hash("sec_fraction", sec_fraction(s[8]));

return 1;
}
Expand All @@ -2623,7 +2635,7 @@ rfc3339(VALUE str, VALUE hash)
{
static const char pat_source[] =
"\\A\\s*(-?\\d{4})-(\\d{2})-(\\d{2})"
"(?:t|\\s)"
"(t|\\s)"
"(\\d{2}):(\\d{2}):(\\d{2})(?:\\.(\\d+))?"
"(z|[-+]\\d{2}:\\d{2})\\s*\\z";
static VALUE pat = Qnil;
Expand Down
18 changes: 18 additions & 0 deletions test/date/test_date_parse.rb
Original file line number Diff line number Diff line change
Expand Up @@ -889,6 +889,24 @@ def test__rfc3339
assert_raise(TypeError) {Date._rfc3339('2001-02-03T04:05:06Z'.to_sym)}
end

def test__rfc3339__deprecated_separator
pat = /Invalid RFC3339 date time separator/

["\t", "\n", "\v", "\f", "\r"].each do |sep|
h = assert_deprecated_warn(pat) do
Date._rfc3339("2001-02-03#{sep}04:05:06Z")
end
assert_equal([2001, 2, 3, 4, 5, 6, 0],
h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset))
end

["T", "t", " "].each do |sep|
assert_deprecated_warn("") do
Date._rfc3339("2001-02-03#{sep}04:05:06Z")
end
end
end

def test__xmlschema
h = Date._xmlschema('2001-02-03')
assert_equal([2001, 2, 3, nil, nil, nil, nil],
Expand Down