[前][次][番号順一覧][スレッド一覧]

ruby-changes:55218

From: nobu <ko1@a...>
Date: Wed, 3 Apr 2019 19:56:41 +0900 (JST)
Subject: [ruby-changes:55218] nobu:r67425 (trunk): date: make zone a substring to copy encoding and taintedness

nobu	2019-04-03 19:56:36 +0900 (Wed, 03 Apr 2019)

  New Revision: 67425

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=67425

  Log:
    date: make zone a substring to copy encoding and taintedness

  Modified files:
    trunk/ext/date/date_core.c
    trunk/ext/date/date_parse.c
    trunk/test/date/test_date_parse.rb
Index: ext/date/date_parse.c
===================================================================
--- ext/date/date_parse.c	(revision 67424)
+++ ext/date/date_parse.c	(revision 67425)
@@ -1862,30 +1862,26 @@ parse_ddd_cb(VALUE m, VALUE hash) https://github.com/ruby/ruby/blob/trunk/ext/date/date_parse.c#L1862
 	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);
     }
Index: ext/date/date_core.c
===================================================================
--- ext/date/date_core.c	(revision 67424)
+++ ext/date/date_core.c	(revision 67425)
@@ -4306,16 +4306,6 @@ date_s__parse_internal(int argc, VALUE * https://github.com/ruby/ruby/blob/trunk/ext/date/date_core.c#L4306
 
     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;
 }
 
Index: test/date/test_date_parse.rb
===================================================================
--- test/date/test_date_parse.rb	(revision 67424)
+++ test/date/test_date_parse.rb	(revision 67425)
@@ -418,7 +418,14 @@ class TestDateParse < Test::Unit::TestCa https://github.com/ruby/ruby/blob/trunk/test/date/test_date_parse.rb#L418
 	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
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]