From 5b2b1130cf7beadedb7176e44b356f157f5a8838 Mon Sep 17 00:00:00 2001 From: nobu Date: Mon, 16 Apr 2018 06:37:42 +0000 Subject: [PATCH] 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 --- string.c | 8 ++++---- test/ruby/test_string.rb | 3 +++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/string.c b/string.c index 25323ce313..a7948224e5 100644 --- a/string.c +++ b/string.c @@ -6289,15 +6289,15 @@ str_undump(VALUE str) 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; diff --git a/test/ruby/test_string.rb b/test/ruby/test_string.rb index fee71791a1..d6356fcfa1 100644 --- a/test/ruby/test_string.rb +++ b/test/ruby/test_string.rb @@ -814,6 +814,9 @@ CODE 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