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

ruby-changes:41162

From: nobu <ko1@a...>
Date: Tue, 22 Dec 2015 15:21:41 +0900 (JST)
Subject: [ruby-changes:41162] nobu:r53235 (trunk): string.c: no exception on dummy encoding

nobu	2015-12-22 15:21:14 +0900 (Tue, 22 Dec 2015)

  New Revision: 53235

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

  Log:
    string.c: no exception on dummy encoding
    
    * string.c (str_compat_and_valid): as scrub does nothing for dummy
      encoding string now, incompatible encoding is not a matter.

  Modified files:
    trunk/ChangeLog
    trunk/string.c
    trunk/test/ruby/test_m17n.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 53234)
+++ ChangeLog	(revision 53235)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue Dec 22 15:21:11 2015  Nobuyoshi Nakada  <nobu@r...>
+
+	* string.c (str_compat_and_valid): as scrub does nothing for dummy
+	  encoding string now, incompatible encoding is not a matter.
+
 Tue Dec 22 14:31:28 2015  Toru Iwase  <tietew@t...>
 
 	* ext/cgi/escape/escape.c (optimized_escape_html): CGI.escapeHTML
Index: string.c
===================================================================
--- string.c	(revision 53234)
+++ string.c	(revision 53235)
@@ -8639,18 +8639,11 @@ str_compat_and_valid(VALUE str, rb_encod https://github.com/ruby/ruby/blob/trunk/string.c#L8639
     if (cr == ENC_CODERANGE_BROKEN) {
 	rb_raise(rb_eArgError, "replacement must be valid byte sequence '%+"PRIsVALUE"'", str);
     }
-    else if (cr == ENC_CODERANGE_7BIT) {
+    else {
 	rb_encoding *e = STR_ENC_GET(str);
-	if (!rb_enc_asciicompat(enc)) {
+	if (cr == ENC_CODERANGE_7BIT ? rb_enc_mbminlen(enc) != 1 : enc != e) {
 	    rb_raise(rb_eEncCompatError, "incompatible character encodings: %s and %s",
-		    rb_enc_name(enc), rb_enc_name(e));
-	}
-    }
-    else { /* ENC_CODERANGE_VALID */
-	rb_encoding *e = STR_ENC_GET(str);
-	if (enc != e) {
-	    rb_raise(rb_eEncCompatError, "incompatible character encodings: %s and %s",
-		    rb_enc_name(enc), rb_enc_name(e));
+		     rb_enc_name(enc), rb_enc_name(e));
 	}
     }
     return str;
Index: test/ruby/test_m17n.rb
===================================================================
--- test/ruby/test_m17n.rb	(revision 53234)
+++ test/ruby/test_m17n.rb	(revision 53235)
@@ -1642,6 +1642,12 @@ class TestM17N < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_m17n.rb#L1642
                  scrub)
   end
 
+  def test_scrub_dummy_encoding
+    s = "\u{3042}".encode("iso-2022-jp")
+    assert_equal(s, s.scrub)
+    assert_equal(s, s.force_encoding("iso-2022-jp").scrub("?"))
+  end
+
   def test_scrub_bang
     str = "\u3042\u3044"
     assert_same(str, str.scrub!)

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

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