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

string.c: rb_fs_setter

* string.c (rb_fs_setter): check and convert $; value at
  assignment.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55990 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2016-08-23 01:15:04 +00:00
parent 2e2f7df725
commit c2bf7e6f7d
3 changed files with 26 additions and 8 deletions

View file

@ -1,3 +1,8 @@
Tue Aug 23 10:15:01 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
* string.c (rb_fs_setter): check and convert $; value at
assignment.
Tue Aug 23 02:09:57 2016 Nobuyoshi Nakada <nobu@ruby-lang.org> Tue Aug 23 02:09:57 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
* string.c (rb_str_split_m): show $; name in error message when it * string.c (rb_str_split_m): show $; name in error message when it

View file

@ -8861,6 +8861,18 @@ rb_str_setter(VALUE val, ID id, VALUE *var)
*var = val; *var = val;
} }
static void
rb_fs_setter(VALUE val, ID id, VALUE *var)
{
val = rb_fs_check(val);
if (!val) {
rb_raise(rb_eTypeError,
"value of %"PRIsVALUE" must be String or Regexp",
rb_id2str(id));
}
*var = val;
}
/* /*
* call-seq: * call-seq:
@ -9879,8 +9891,8 @@ Init_String(void)
rb_define_method(rb_cString, "ascii_only?", rb_str_is_ascii_only_p, 0); rb_define_method(rb_cString, "ascii_only?", rb_str_is_ascii_only_p, 0);
rb_fs = Qnil; rb_fs = Qnil;
rb_define_variable("$;", &rb_fs); rb_define_hooked_variable("$;", &rb_fs, 0, rb_fs_setter);
rb_define_variable("$-F", &rb_fs); rb_define_hooked_variable("$-F", &rb_fs, 0, rb_fs_setter);
rb_cSymbol = rb_define_class("Symbol", rb_cObject); rb_cSymbol = rb_define_class("Symbol", rb_cObject);
rb_include_module(rb_cSymbol, rb_mComparable); rb_include_module(rb_cSymbol, rb_mComparable);

View file

@ -1389,15 +1389,16 @@ CODE
assert_equal([], "".split(//, 1)) assert_equal([], "".split(//, 1))
assert_equal("[2, 3]", [1,2,3].slice!(1,10000).inspect, "moved from btest/knownbug") assert_equal("[2, 3]", [1,2,3].slice!(1,10000).inspect, "moved from btest/knownbug")
$; = []
assert_raise_with_message(TypeError, /\$;/) {
"".split
}
ensure ensure
$; = fs $; = fs
end end
def test_fs
assert_raise_with_message(TypeError, /\$;/) {
$; = []
}
end
def test_split_encoding def test_split_encoding
bug6206 = '[ruby-dev:45441]' bug6206 = '[ruby-dev:45441]'
Encoding.list.each do |enc| Encoding.list.each do |enc|