1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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
This commit is contained in:
nobu 2015-12-22 06:21:14 +00:00
parent 10a129cee7
commit 9da8a29760
3 changed files with 14 additions and 10 deletions

View file

@ -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

View file

@ -8639,16 +8639,9 @@ 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) {
else {
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 */
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));
}

View file

@ -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!)