summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-12-22 06:21:14 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-12-22 06:21:14 +0000
commit9da8a2976094dcc69ee6646727de14721d9845ef (patch)
tree49210c7b0857630d64bb152cc536f9f0111e1380
parent10a129cee72512315e84d5b29a8ca471058e80ff (diff)
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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53235 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--string.c13
-rw-r--r--test/ruby/test_m17n.rb6
3 files changed, 14 insertions, 10 deletions
diff --git a/ChangeLog b/ChangeLog
index 3087a4cd95..8ce4a133dc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Tue Dec 22 15:21:11 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * 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@tietew.net>
* ext/cgi/escape/escape.c (optimized_escape_html): CGI.escapeHTML
diff --git a/string.c b/string.c
index 4ab89a8e2f..4f9fe51f9f 100644
--- a/string.c
+++ b/string.c
@@ -8639,18 +8639,11 @@ str_compat_and_valid(VALUE str, rb_encoding *enc)
if (cr == ENC_CODERANGE_BROKEN) {
rb_raise(rb_eArgError, "replacement must be valid byte sequence '%+"PRIsVALUE"'", str);
}
- else if (cr == ENC_CODERANGE_7BIT) {
- rb_encoding *e = STR_ENC_GET(str);
- if (!rb_enc_asciicompat(enc)) {
- rb_raise(rb_eEncCompatError, "incompatible character encodings: %s and %s",
- rb_enc_name(enc), rb_enc_name(e));
- }
- }
- else { /* ENC_CODERANGE_VALID */
+ else {
rb_encoding *e = STR_ENC_GET(str);
- if (enc != e) {
+ 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));
+ rb_enc_name(enc), rb_enc_name(e));
}
}
return str;
diff --git a/test/ruby/test_m17n.rb b/test/ruby/test_m17n.rb
index 9f96652083..3a45f1f028 100644
--- a/test/ruby/test_m17n.rb
+++ b/test/ruby/test_m17n.rb
@@ -1642,6 +1642,12 @@ class TestM17N < Test::Unit::TestCase
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!)