summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2019-04-03 10:56:36 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2019-04-03 10:56:36 +0000
commit1329c7cdca5cca07e8680a28724b3f192144f04e (patch)
tree369dbfb983f6e33adc669c8d02f0cb4a2f469ffb /ext
parentf0204a254789608edc46515f181b1f52ec106442 (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
Diffstat (limited to 'ext')
-rw-r--r--ext/date/date_core.c10
-rw-r--r--ext/date/date_parse.c32
2 files changed, 14 insertions, 28 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);
}