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

ruby-changes:36764

From: nobu <ko1@a...>
Date: Mon, 15 Dec 2014 16:19:36 +0900 (JST)
Subject: [ruby-changes:36764] nobu:r48845 (trunk): string.c: fix coderange for non-endianness string

nobu	2014-12-15 16:19:25 +0900 (Mon, 15 Dec 2014)

  New Revision: 48845

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

  Log:
    string.c: fix coderange for non-endianness string
    
    * string.c (rb_enc_str_coderange): dummy wchar, non-endianness
      encoding string cannot be ascii only.
      [ruby-core:66835] [Bug #10598]

  Modified files:
    trunk/ChangeLog
    trunk/string.c
    trunk/test/ruby/test_m17n.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 48844)
+++ ChangeLog	(revision 48845)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Mon Dec 15 16:19:23 2014  Nobuyoshi Nakada  <nobu@r...>
+
+	* string.c (rb_enc_str_coderange): dummy wchar, non-endianness
+	  encoding string cannot be ascii only.
+	  [ruby-core:66835] [Bug #10598]
+
 Sun Dec 14 20:11:42 2014  Nobuyoshi Nakada  <nobu@r...>
 
 	* parse.y (primary): restore current_arg so that circular
Index: string.c
===================================================================
--- string.c	(revision 48844)
+++ string.c	(revision 48845)
@@ -487,8 +487,15 @@ rb_enc_str_coderange(VALUE str) https://github.com/ruby/ruby/blob/trunk/string.c#L487
     int cr = ENC_CODERANGE(str);
 
     if (cr == ENC_CODERANGE_UNKNOWN) {
-	rb_encoding *enc = STR_ENC_GET(str);
-        cr = coderange_scan(RSTRING_PTR(str), RSTRING_LEN(str), enc);
+	int encidx = ENCODING_GET(str);
+	rb_encoding *enc = rb_enc_from_index(encidx);
+	if (rb_enc_mbminlen(enc) > 1 && rb_enc_dummy_p(enc)) {
+	    cr = ENC_CODERANGE_BROKEN;
+	}
+	else {
+	    cr = coderange_scan(RSTRING_PTR(str), RSTRING_LEN(str),
+				get_actual_encoding(encidx, str));
+	}
         ENC_CODERANGE_SET(str, cr);
     }
     return cr;
Index: test/ruby/test_m17n.rb
===================================================================
--- test/ruby/test_m17n.rb	(revision 48844)
+++ test/ruby/test_m17n.rb	(revision 48845)
@@ -260,6 +260,14 @@ class TestM17N < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_m17n.rb#L260
     end
   end
 
+  def test_utf_without_bom_asciionly
+    bug10598 = '[ruby-core:66835] [Bug #10598]'
+    encs = [Encoding::UTF_16, Encoding::UTF_32].find_all {|enc|
+      "abcd".force_encoding(enc).ascii_only?
+    }
+    assert_empty(encs, bug10598)
+  end
+
   def test_object_utf16_32_inspect
     EnvUtil.suppress_warning do
       begin

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

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