From cda4374689ff8569444312c3c09217a38ee8edc0 Mon Sep 17 00:00:00 2001 From: Oskar Eichler Date: Fri, 28 Aug 2026 00:23:56 +0300 Subject: [PATCH 1/2] Match ID string literal bytes without encoding conflicts --- lib/net/imap/command_data.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/net/imap/command_data.rb b/lib/net/imap/command_data.rb index 1fd0dc30..cab59a97 100644 --- a/lib/net/imap/command_data.rb +++ b/lib/net/imap/command_data.rb @@ -459,7 +459,7 @@ def valid_nstring?(str) # coerces using +to_s+ def string(str) str = str.to_s - if str =~ LITERAL_REGEX + if str.b.match?(LITERAL_REGEX) Literal.new(str) else QuotedString.new(str) From 3b281117e8c33d8ca7df11eadfc344e31b01517b Mon Sep 17 00:00:00 2001 From: Oskar Eichler Date: Sun, 30 Aug 2026 14:38:12 +0700 Subject: [PATCH 2/2] Test non-ASCII string formatting --- test/net/imap/test_command_data.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/net/imap/test_command_data.rb b/test/net/imap/test_command_data.rb index d6928acf..a36077c9 100644 --- a/test/net/imap/test_command_data.rb +++ b/test/net/imap/test_command_data.rb @@ -161,6 +161,14 @@ def send_data(*data, tag: TAG) class StringFormatterTest < Net::IMAP::TestCase include Net::IMAP::StringFormatter + test "string selects a literal for non-ASCII text" do + value = "日本語" + formatted = string(value) + + assert_kind_of Literal, formatted + assert_equal value.b, formatted.data + end + test "literal_or_literal8" do assert_kind_of Literal, literal_or_literal8("simple\r\n") assert_kind_of Literal8, literal_or_literal8("has NULL \0")