diff --git a/ext/date/date_parse.c b/ext/date/date_parse.c index 597c25a..883f74e 100644 --- a/ext/date/date_parse.c +++ b/ext/date/date_parse.c @@ -2098,6 +2098,7 @@ date__xmlschema(VALUE str) rb_match_busy(backref); hash = rb_hash_new(); + str = rb_str_dup(str); if (xmlschema_datetime(str, hash)) goto ok; @@ -2169,6 +2170,7 @@ date__rfc2822(VALUE str) rb_match_busy(backref); hash = rb_hash_new(); + str = rb_str_dup(str); rfc2822(str, hash); rb_backref_set(backref); return hash; @@ -2315,6 +2317,7 @@ date__httpdate(VALUE str) rb_match_busy(backref); hash = rb_hash_new(); + str = rb_str_dup(str); if (httpdate_type1(str, hash)) goto ok; diff --git a/test/date/test_date_parse.rb b/test/date/test_date_parse.rb index fb54d14..3ef5716 100644 --- a/test/date/test_date_parse.rb +++ b/test/date/test_date_parse.rb @@ -1019,6 +1019,20 @@ class TestDateParse < Test::Unit::TestCase assert_equal(Date::ITALY + 10, d.start) end + def test_date_xmlschema_does_not_mutate + x = "2006-02-13T10:37:00.000-05:00" + y = x.dup + Date.xmlschema x + assert_equal y, x + end + + def test_datetime_xmlschema_does_not_mutate + x = "2006-02-13T10:37:00.000-05:00" + y = x.dup + DateTime.xmlschema x + assert_equal y, x + end + def test_rfc2822 assert_instance_of(Date, Date.rfc2822) assert_instance_of(DateTime, DateTime.rfc2822) @@ -1034,6 +1048,17 @@ class TestDateParse < Test::Unit::TestCase assert_equal(Date::ITALY + 10, d.start) end + def test_rfc2822_does_not_mutate + x = 'Mon, 1 Jan -4712 00:00:00 +0000' + y = x.dup + + Date.rfc2822 x + assert_equal y, x + + DateTime.rfc2822 x + assert_equal y, x + end + def test_httpdate assert_instance_of(Date, Date.httpdate) assert_instance_of(DateTime, DateTime.httpdate) @@ -1047,6 +1072,17 @@ class TestDateParse < Test::Unit::TestCase assert_equal(Date::ITALY + 10, d.start) end + def test_httpdate_does_not_mutate + x = "Mon, 01 Jan -4712 00:00:00 GMT" + y = x.dup + + Date.httpdate x + assert_equal y, x + + DateTime.httpdate x + assert_equal y, x + end + def test_jisx0301 assert_instance_of(Date, Date.jisx0301) assert_instance_of(DateTime, DateTime.jisx0301)