diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2019-04-03 10:56:36 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2019-04-03 10:56:36 +0000 |
commit | 1329c7cdca5cca07e8680a28724b3f192144f04e (patch) | |
tree | 369dbfb983f6e33adc669c8d02f0cb4a2f469ffb | |
parent | f0204a254789608edc46515f181b1f52ec106442 (diff) |
date: make zone a substring to copy encoding and taintedness
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67425 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ext/date/date_core.c | 10 | ||||
-rw-r--r-- | ext/date/date_parse.c | 32 | ||||
-rw-r--r-- | test/date/test_date_parse.rb | 9 |
3 files changed, 22 insertions, 29 deletions
diff --git a/ext/date/date_core.c b/ext/date/date_core.c index 88be90b6bc..812548aeaa 100644 --- a/ext/date/date_core.c +++ b/ext/date/date_core.c @@ -4306,16 +4306,6 @@ date_s__parse_internal(int argc, VALUE *argv, VALUE klass) hash = date__parse(vstr, vcomp); - { - VALUE zone = ref_hash("zone"); - - if (!NIL_P(zone)) { - rb_enc_copy(zone, vstr); - OBJ_INFECT(zone, vstr); - set_hash("zone", zone); - } - } - return hash; } diff --git a/ext/date/date_parse.c b/ext/date/date_parse.c index ae3e90a3ae..207b00ce3c 100644 --- a/ext/date/date_parse.c +++ b/ext/date/date_parse.c @@ -1862,30 +1862,26 @@ parse_ddd_cb(VALUE m, VALUE hash) set_hash("zone", s5); if (*cs5 == '[') { - VALUE vbuf = 0; - char *buf = ALLOCV_N(char, vbuf, l5 + 1); - char *s1, *s2, *s3; + const char *s1, *s2; VALUE zone; - memcpy(buf, cs5, l5); - buf[l5 - 1] = '\0'; - - s1 = buf + 1; - s2 = strchr(buf, ':'); + l5 -= 2; + s1 = cs5 + 1; + s2 = memchr(s1, ':', l5); if (s2) { - *s2 = '\0'; s2++; + zone = rb_str_subseq(s5, s2 - cs5, l5 - (s2 - s1)); + s5 = rb_str_subseq(s5, 1, s2 - s1); } - if (s2) - s3 = s2; - else - s3 = s1; - zone = rb_str_new2(s3); + else { + zone = rb_str_subseq(s5, 1, l5); + if (isdigit((unsigned char)*s1)) + s5 = rb_str_append(rb_str_new_cstr("+"), zone); + else + s5 = zone; + } set_hash("zone", zone); - if (isdigit((unsigned char)*s1)) - *--s1 = '+'; - set_hash("offset", date_zone_to_diff(rb_str_new2(s1))); - ALLOCV_END(vbuf); + set_hash("offset", date_zone_to_diff(s5)); } RB_GC_GUARD(s5); } diff --git a/test/date/test_date_parse.rb b/test/date/test_date_parse.rb index c62554d126..7907295bf4 100644 --- a/test/date/test_date_parse.rb +++ b/test/date/test_date_parse.rb @@ -418,7 +418,14 @@ class TestDateParse < Test::Unit::TestCase a[1] = -1 a[2] = h[:yday] end - assert_equal(y, a, format('<failed at line %d>', l)) + l = format('<failed at line %d>', l) + assert_equal(y, a, l) + if y[6] + h = Date._parse(x[0].dup.taint, *x[1..-1]) + assert_equal(y[6], h[:zone], l) + assert_equal(y[6].encoding, h[:zone].encoding, l) + assert_predicate(h[:zone], :tainted?, l) + end end end |