aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-09-29 08:15:50 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-09-29 08:15:50 +0000
commitf5bb2d991ebe0b16d66d6a97f025f6f63c079ab6 (patch)
tree2bf7662447faa12cda250ac757fc5ffa5f93822b
parent6164e8691a4378bf9cc2c159e4bb01e47f12d3cf (diff)
downloadruby-f5bb2d991ebe0b16d66d6a97f025f6f63c079ab6.tar.gz
string.c: ASCII-incompatible is not ASCII only
* string.c (tr_trans): ASCII-incompatible encoding strings cannot be ASCII-only even if valid. [ruby-core:83056] [Bug #13950] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60060 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--string.c2
-rw-r--r--test/ruby/test_string.rb7
2 files changed, 7 insertions, 2 deletions
diff --git a/string.c b/string.c
index 7e7ae7f0a8..e1bd9a052e 100644
--- a/string.c
+++ b/string.c
@@ -6637,7 +6637,7 @@ tr_trans(VALUE str, VALUE src, VALUE repl, int sflag)
}
}
- if (cr == ENC_CODERANGE_VALID)
+ if (cr == ENC_CODERANGE_VALID && rb_enc_asciicompat(e1))
cr = ENC_CODERANGE_7BIT;
str_modify_keep_cr(str);
s = RSTRING_PTR(str); send = RSTRING_END(str);
diff --git a/test/ruby/test_string.rb b/test/ruby/test_string.rb
index b1f3c3cfcb..ec90193546 100644
--- a/test/ruby/test_string.rb
+++ b/test/ruby/test_string.rb
@@ -2063,8 +2063,13 @@ CODE
assert_equal(false, "\u3041\u3042".tr("\u3041", "a").ascii_only?)
bug6156 = '[ruby-core:43335]'
+ bug13950 = '[ruby-core:83056] [Bug #13950]'
str, range, star = %w[b a-z *].map{|s|s.encode("utf-16le")}
- assert_equal(star, str.tr(range, star), bug6156)
+ result = str.tr(range, star)
+ assert_equal(star, result, bug6156)
+ assert_not_predicate(str, :ascii_only?)
+ assert_not_predicate(star, :ascii_only?)
+ assert_not_predicate(result, :ascii_only?, bug13950)
end
def test_tr!