зеркало из https://github.com/github/ruby.git
string.c: fix checking order
* string.c (str_undump): check for suffix before if Unicode escape conflicts with it. the message "but used force_encoding" sounds strange when it is not used. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63162 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
5bae48bd56
Коммит
5b2b1130cf
8
string.c
8
string.c
|
@ -6289,15 +6289,15 @@ str_undump(VALUE str)
|
||||||
int encidx;
|
int encidx;
|
||||||
ptrdiff_t size;
|
ptrdiff_t size;
|
||||||
|
|
||||||
if (utf8) {
|
|
||||||
rb_raise(rb_eRuntimeError, "dumped string contained Unicode escape but used force_encoding");
|
|
||||||
}
|
|
||||||
|
|
||||||
size = rb_strlen_lit(".force_encoding(\"");
|
size = rb_strlen_lit(".force_encoding(\"");
|
||||||
if (s_end - s <= size) goto invalid_format;
|
if (s_end - s <= size) goto invalid_format;
|
||||||
if (memcmp(s, ".force_encoding(\"", size) != 0) goto invalid_format;
|
if (memcmp(s, ".force_encoding(\"", size) != 0) goto invalid_format;
|
||||||
s += size;
|
s += size;
|
||||||
|
|
||||||
|
if (utf8) {
|
||||||
|
rb_raise(rb_eRuntimeError, "dumped string contained Unicode escape but used force_encoding");
|
||||||
|
}
|
||||||
|
|
||||||
encname = s;
|
encname = s;
|
||||||
s = memchr(s, '"', s_end-s);
|
s = memchr(s, '"', s_end-s);
|
||||||
size = s - encname;
|
size = s - encname;
|
||||||
|
|
|
@ -814,6 +814,9 @@ CODE
|
||||||
assert_raise(RuntimeError) { S('"\xA"').undump }
|
assert_raise(RuntimeError) { S('"\xA"').undump }
|
||||||
assert_raise(RuntimeError) { S('"\\"').undump }
|
assert_raise(RuntimeError) { S('"\\"').undump }
|
||||||
assert_raise(RuntimeError) { S(%("\0")).undump }
|
assert_raise(RuntimeError) { S(%("\0")).undump }
|
||||||
|
assert_raise_with_message(RuntimeError, /invalid/) {
|
||||||
|
'"\\u{007F}".xxxxxx'.undump
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_dup
|
def test_dup
|
||||||
|
|
Загрузка…
Ссылка в новой задаче