From 1329c7cdca5cca07e8680a28724b3f192144f04e Mon Sep 17 00:00:00 2001 From: nobu Date: Wed, 3 Apr 2019 10:56:36 +0000 Subject: 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 --- ext/date/date_core.c | 10 ---------- ext/date/date_parse.c | 32 ++++++++++++++------------------ 2 files changed, 14 insertions(+), 28 deletions(-) (limited to 'ext') 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); } -- cgit v1.2.3