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

ruby-changes:4150

From: ko1@a...
Date: Fri, 29 Feb 2008 18:19:36 +0900 (JST)
Subject: [ruby-changes:4150] matz - Ruby:r15640 (trunk): * time.c (time_strftime): format should be ascii compatible.

matz	2008-02-29 18:19:15 +0900 (Fri, 29 Feb 2008)

  New Revision: 15640

  Modified files:
    trunk/ChangeLog
    trunk/parse.y
    trunk/re.c
    trunk/string.c
    trunk/test/ruby/test_utf16.rb
    trunk/time.c

  Log:
    * time.c (time_strftime): format should be ascii compatible.
    
    * parse.y (rb_intern3): non ASCII compatible symbols.
    
    * re.c (rb_reg_regsub): add encoding check.
    
    * string.c (rb_str_chomp_bang): ditto.
    
    * test/ruby/test_utf16.rb (TestUTF16::test_chomp): raises exception.

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/time.c?r1=15640&r2=15639&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/string.c?r1=15640&r2=15639&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/parse.y?r1=15640&r2=15639&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=15640&r2=15639&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/test/ruby/test_utf16.rb?r1=15640&r2=15639&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/re.c?r1=15640&r2=15639&diff_format=u

Index: time.c
===================================================================
--- time.c	(revision 15639)
+++ time.c	(revision 15640)
@@ -12,6 +12,7 @@
 #include "ruby/ruby.h"
 #include <sys/types.h>
 #include <time.h>
+#include "ruby/encoding.h"
 
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
@@ -2077,6 +2078,9 @@
 	time_get_tm(time, tobj->gmt);
     }
     StringValue(format);
+    if (!rb_enc_str_asciicompat_p(format)) {
+	rb_raise(rb_eArgError, "format should have ASCII compatible encoding");
+    }
     format = rb_str_new4(format);
     fmt = RSTRING_PTR(format);
     len = RSTRING_LEN(format);
Index: re.c
===================================================================
--- re.c	(revision 15639)
+++ re.c	(revision 15640)
@@ -2960,6 +2960,7 @@
     rb_encoding *str_enc = rb_enc_get(str);
     rb_encoding *src_enc = rb_enc_get(src);
 
+    rb_enc_check(str, src);
     p = s = RSTRING_PTR(str);
     e = s + RSTRING_LEN(str);
 
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 15639)
+++ ChangeLog	(revision 15640)
@@ -1,3 +1,15 @@
+Fri Feb 29 18:08:43 2008  Yukihiro Matsumoto  <matz@r...>
+
+	* time.c (time_strftime): format should be ascii compatible.
+
+	* parse.y (rb_intern3): non ASCII compatible symbols.
+
+	* re.c (rb_reg_regsub): add encoding check.
+
+	* string.c (rb_str_chomp_bang): ditto.
+
+	* test/ruby/test_utf16.rb (TestUTF16::test_chomp): raises exception.
+
 Fri Feb 29 15:16:31 2008  Yukihiro Matsumoto  <matz@r...>
 
 	* string.c (rb_str_rpartition): calculation was done in byte indexing.
Index: string.c
===================================================================
--- string.c	(revision 15639)
+++ string.c	(revision 15640)
@@ -5273,6 +5273,7 @@
 	rs = rb_rs;
 	if (rs == rb_default_rs) {
 	  smart_chomp:
+	    rb_enc_check(str, rs);
 	    rb_str_modify(str);
 	    if (RSTRING_PTR(str)[len-1] == '\n') {
 		STR_DEC_LEN(str);
@@ -5648,6 +5649,11 @@
 static VALUE
 rb_str_hex(VALUE str)
 {
+    rb_encoding *enc = rb_enc_get(str);
+
+    if (!rb_enc_asciicompat(enc)) {
+	rb_raise(rb_eArgError, "ASCII incompatible encoding: %s", rb_enc_name(enc));
+    }
     return rb_str_to_inum(str, 16, Qfalse);
 }
 
@@ -5669,6 +5675,11 @@
 static VALUE
 rb_str_oct(VALUE str)
 {
+    rb_encoding *enc = rb_enc_get(str);
+
+    if (!rb_enc_asciicompat(enc)) {
+	rb_raise(rb_eArgError, "ASCII incompatible encoding: %s", rb_enc_name(enc));
+    }
     return rb_str_to_inum(str, -8, Qfalse);
 }
 
Index: parse.y
===================================================================
--- parse.y	(revision 15639)
+++ parse.y	(revision 15640)
@@ -9008,6 +9008,10 @@
     if (st_lookup(global_symbols.sym_id, str, (st_data_t *)&id))
 	return id;
 
+    if (rb_cString && !rb_enc_asciicompat(enc)) {
+	id = ID_JUNK;
+	goto new_id;
+    }
     last = len-1;
     id = 0;
     switch (*m) {
Index: test/ruby/test_utf16.rb
===================================================================
--- test/ruby/test_utf16.rb	(revision 15639)
+++ test/ruby/test_utf16.rb	(revision 15640)
@@ -132,13 +132,21 @@
   end
 
   def test_hex
-    s1 = "f\0f\0".force_encoding("utf-16le")
-    assert_equal(255, s1.hex, "#{encdump s1}.hex")
+    assert_raise(ArgumentError) {
+      "ff".encode("utf-16le").hex
+    }
+    assert_raise(ArgumentError) {
+      "ff".encode("utf-16be").hex
+    }
   end
 
   def test_oct
-    assert_equal(077, "77".encode("utf-16le").oct)
-    assert_equal(077, "77".encode("utf-16be").oct)
+    assert_raise(ArgumentError) {
+      "77".encode("utf-16le").oct
+    }
+    assert_raise(ArgumentError) {
+      "77".encode("utf-16be").oct
+    }
   end
 
   def test_count
@@ -224,7 +232,9 @@
 
   def test_chomp
     s = "\1\n".force_encoding("utf-16be")
-    assert_str_equal(s, s.chomp, "#{encdump s}.chomp")
+    assert_raise(ArgumentError, "#{encdump s}.chomp") {
+      s.chomp
+    }
   end
 
   def test_succ

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

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