mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* transcode.c (rb_econv_prepare_opts): raise ArgumentError if
a broken string is specified as a replacement. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19316 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
965ff82341
commit
2cc9b488a0
3 changed files with 18 additions and 1 deletions
|
@ -1,3 +1,8 @@
|
|||
Sat Sep 13 03:44:52 2008 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* transcode.c (rb_econv_prepare_opts): raise ArgumentError if
|
||||
a broken string is specified as a replacement.
|
||||
|
||||
Sat Sep 13 03:31:05 2008 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* iseq.c (iseq_s_compile_file): use rb_file_open_str.
|
||||
|
|
|
@ -871,4 +871,11 @@ class TestEncodingConverter < Test::Unit::TestCase
|
|||
assert_equal([[iso88591,utf8], "universal_newline", [utf8,utf32be]],
|
||||
Encoding::Converter.search_convpath("ISO-8859-1", "UTF-32BE", universal_newline: true))
|
||||
end
|
||||
|
||||
def test_invalid_replace
|
||||
assert_raise(ArgumentError) {
|
||||
broken = "\x80".force_encoding("euc-jp")
|
||||
"".encode("euc-jp", :undef => :replace, :replace => broken)
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2254,7 +2254,6 @@ econv_opts(VALUE opt)
|
|||
}
|
||||
else if (v==sym_replace) {
|
||||
ecflags |= ECONV_INVALID_REPLACE;
|
||||
v = rb_hash_aref(opt, sym_replace);
|
||||
}
|
||||
else {
|
||||
rb_raise(rb_eArgError, "unknown value for invalid character option");
|
||||
|
@ -2315,6 +2314,12 @@ rb_econv_prepare_opts(VALUE opthash, VALUE *opts)
|
|||
VALUE v = rb_hash_aref(opthash, sym_replace);
|
||||
if (!NIL_P(v)) {
|
||||
StringValue(v);
|
||||
if (rb_enc_str_coderange(v) == ENC_CODERANGE_BROKEN) {
|
||||
VALUE dumped = rb_str_dump(v);
|
||||
rb_raise(rb_eArgError, "replacement string is broken: %s as %s",
|
||||
StringValueCStr(dumped),
|
||||
rb_enc_name(rb_enc_get(v)));
|
||||
}
|
||||
v = rb_str_new_frozen(v);
|
||||
newhash = rb_hash_new();
|
||||
rb_hash_aset(newhash, sym_replace, v);
|
||||
|
|
Loading…
Reference in a new issue