From b710f96b5aaeb6c153e4b1a7e1b46c4521214126 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Sat, 16 Dec 2023 13:48:49 +0900 Subject: [PATCH] [Bug #20068] Encoding does not matter to empty strings --- string.c | 2 +- test/ruby/test_string.rb | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/string.c b/string.c index cfad52d2e3..c38473481f 100644 --- a/string.c +++ b/string.c @@ -3586,7 +3586,7 @@ rb_str_prepend_multi(int argc, VALUE *argv, VALUE str) st_index_t rb_str_hash(VALUE str) { - int e = ENCODING_GET(str); + int e = RSTRING_LEN(str) ? ENCODING_GET(str) : 0; if (e && is_ascii_string(str)) { e = 0; } diff --git a/test/ruby/test_string.rb b/test/ruby/test_string.rb index 1c7e085630..4d5dea7328 100644 --- a/test/ruby/test_string.rb +++ b/test/ruby/test_string.rb @@ -1344,6 +1344,7 @@ CODE assert_not_equal(S("a").hash, S("a\0").hash, bug4104) bug9172 = '[ruby-core:58658] [Bug #9172]' assert_not_equal(S("sub-setter").hash, S("discover").hash, bug9172) + assert_equal(S("").hash, S("".encode(Encoding::UTF_32BE)).hash) end def test_hex