ruby-changes:50955
From: nobu <ko1@a...>
Date: Mon, 16 Apr 2018 15:37:48 +0900 (JST)
Subject: [ruby-changes:50955] nobu:r63162 (trunk): string.c: fix checking order
nobu 2018-04-16 15:37:42 +0900 (Mon, 16 Apr 2018) New Revision: 63162 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=63162 Log: 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. Modified files: trunk/string.c trunk/test/ruby/test_string.rb Index: string.c =================================================================== --- string.c (revision 63161) +++ string.c (revision 63162) @@ -6289,15 +6289,15 @@ str_undump(VALUE str) https://github.com/ruby/ruby/blob/trunk/string.c#L6289 int encidx; ptrdiff_t size; - if (utf8) { - rb_raise(rb_eRuntimeError, "dumped string contained Unicode escape but used force_encoding"); - } - size = rb_strlen_lit(".force_encoding(\""); if (s_end - s <= size) goto invalid_format; if (memcmp(s, ".force_encoding(\"", size) != 0) goto invalid_format; s += size; + if (utf8) { + rb_raise(rb_eRuntimeError, "dumped string contained Unicode escape but used force_encoding"); + } + encname = s; s = memchr(s, '"', s_end-s); size = s - encname; Index: test/ruby/test_string.rb =================================================================== --- test/ruby/test_string.rb (revision 63161) +++ test/ruby/test_string.rb (revision 63162) @@ -814,6 +814,9 @@ CODE https://github.com/ruby/ruby/blob/trunk/test/ruby/test_string.rb#L814 assert_raise(RuntimeError) { S('"\xA"').undump } assert_raise(RuntimeError) { S('"\\"').undump } assert_raise(RuntimeError) { S(%("\0")).undump } + assert_raise_with_message(RuntimeError, /invalid/) { + '"\\u{007F}".xxxxxx'.undump + } end def test_dup -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/