From f18047c290389b0593db57b66262689b74cbeeeb Mon Sep 17 00:00:00 2001 From: Akinori MUSHA Date: Wed, 5 Jun 2013 21:30:47 +0900 Subject: [PATCH] * string.c (String#b): Check the code range so ascii_only? on a result string returns the correct value. --- ChangeLog | 5 +++++ string.c | 4 +++- test/ruby/test_m17n.rb | 2 ++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 863e309..6257979 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Wed Jun 5 21:20:11 2013 Akinori MUSHA + + * string.c (String#b): Check the code range so ascii_only? on a + result string returns the correct value. + Wed Jun 5 09:46:46 2013 NARUSE, Yui * test/fileutils/test_fileutils.rb (TestFileUtils#test_mkdir): add diff --git a/string.c b/string.c index 6aeb029..ed55095 100644 --- a/string.c +++ b/string.c @@ -7622,9 +7622,11 @@ static VALUE rb_str_b(VALUE str) { VALUE str2 = str_alloc(rb_cString); + int cr; str_replace_shared_without_enc(str2, str); OBJ_INFECT(str2, str); - ENC_CODERANGE_SET(str2, ENC_CODERANGE_VALID); + cr = coderange_scan(RSTRING_PTR(str2), RSTRING_LEN(str2), 0); + ENC_CODERANGE_SET(str2, cr); return str2; } diff --git a/test/ruby/test_m17n.rb b/test/ruby/test_m17n.rb index 98f79b3..edc8e4c 100644 --- a/test/ruby/test_m17n.rb +++ b/test/ruby/test_m17n.rb @@ -1488,6 +1488,8 @@ class TestM17N < Test::Unit::TestCase assert_equal(true, s.b.tainted?) s.untrust assert_equal(true, s.b.untrusted?) + s = "abc".b + assert_equal(true, s.b.ascii_only?) end def test_scrub -- 1.8.2.3