зеркало из https://github.com/github/ruby.git
string.c: proper exception
* string.c (rb_str_split_m): raise ArgumentError at broken string not RegexpError, as Regexp is not involved in. [ruby-core:68229] [Bug #10886] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49695 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
8c13c9cb0e
Коммит
a10fdc9270
|
@ -1,3 +1,9 @@
|
|||
Mon Feb 23 15:26:39 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* string.c (rb_str_split_m): raise ArgumentError at broken string
|
||||
not RegexpError, as Regexp is not involved in.
|
||||
[ruby-core:68229] [Bug #10886]
|
||||
|
||||
Mon Feb 23 07:25:29 2015 Benoit Daloze <eregontp@gmail.com>
|
||||
|
||||
* time.c: Zone encoding should be US-ASCII if all 7-bits. Fix r46907.
|
||||
|
|
4
string.c
4
string.c
|
@ -6387,10 +6387,11 @@ rb_str_split_m(int argc, VALUE *argv, VALUE str)
|
|||
}
|
||||
else {
|
||||
fs_set:
|
||||
spat = get_pat_quoted(spat, 1);
|
||||
spat = get_pat_quoted(spat, 0);
|
||||
if (BUILTIN_TYPE(spat) == T_STRING) {
|
||||
rb_encoding *enc2 = STR_ENC_GET(spat);
|
||||
|
||||
mustnot_broken(spat);
|
||||
split_type = string;
|
||||
if (RSTRING_LEN(spat) == 0) {
|
||||
/* Special case - split into chars */
|
||||
|
@ -6485,7 +6486,6 @@ rb_str_split_m(int argc, VALUE *argv, VALUE str)
|
|||
long slen = RSTRING_LEN(spat);
|
||||
|
||||
mustnot_broken(str);
|
||||
mustnot_broken(spat);
|
||||
enc = rb_enc_check(str, spat);
|
||||
while (ptr < eptr &&
|
||||
(end = rb_memsearch(sptr, slen, ptr, eptr - ptr, enc)) >= 0) {
|
||||
|
|
|
@ -1345,14 +1345,18 @@ class TestString < Test::Unit::TestCase
|
|||
assert_equal([], "".split(//, 1))
|
||||
|
||||
assert_equal("[2, 3]", [1,2,3].slice!(1,10000).inspect, "moved from btest/knownbug")
|
||||
end
|
||||
|
||||
def test_split_encoding
|
||||
bug6206 = '[ruby-dev:45441]'
|
||||
Encoding.list.each do |enc|
|
||||
next unless enc.ascii_compatible?
|
||||
s = S("a:".force_encoding(enc))
|
||||
assert_equal([enc]*2, s.split(":", 2).map(&:encoding), bug6206)
|
||||
end
|
||||
end
|
||||
|
||||
def test_split_wchar
|
||||
bug8642 = '[ruby-core:56036] [Bug #8642]'
|
||||
[
|
||||
Encoding::UTF_16BE, Encoding::UTF_16LE,
|
||||
|
@ -1365,6 +1369,20 @@ class TestString < Test::Unit::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
def test_split_invalid_sequence
|
||||
bug10886 = '[ruby-core:68229] [Bug #10886]'
|
||||
broken = S("\xa1".force_encoding("utf-8"))
|
||||
assert_raise(ArgumentError, bug10886) {
|
||||
S("a,b").split(broken)
|
||||
}
|
||||
end
|
||||
|
||||
def test_split_invalid_argument
|
||||
assert_raise(TypeError) {
|
||||
S("a,b").split(BasicObject.new)
|
||||
}
|
||||
end
|
||||
|
||||
def test_squeeze
|
||||
assert_equal(S("abc"), S("aaabbbbccc").squeeze)
|
||||
assert_equal(S("aa bb cc"), S("aa bb cc").squeeze(S(" ")))
|
||||
|
|
Загрузка…
Ссылка в новой задаче