Skip to content

Commit 1738756

Browse files
authored
🔀 Merge pull request #740 from OskarEichler/codex/formatting-imap
Match ID string literal bytes without encoding conflicts
2 parents e02f9cb + 3b28111 commit 1738756

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

lib/net/imap/command_data.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ def valid_nstring?(str)
459459
# coerces using +to_s+
460460
def string(str)
461461
str = str.to_s
462-
if str =~ LITERAL_REGEX
462+
if str.b.match?(LITERAL_REGEX)
463463
Literal.new(str)
464464
else
465465
QuotedString.new(str)

test/net/imap/test_command_data.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,14 @@ def send_data(*data, tag: TAG)
161161
class StringFormatterTest < Net::IMAP::TestCase
162162
include Net::IMAP::StringFormatter
163163

164+
test "string selects a literal for non-ASCII text" do
165+
value = "日本語"
166+
formatted = string(value)
167+
168+
assert_kind_of Literal, formatted
169+
assert_equal value.b, formatted.data
170+
end
171+
164172
test "literal_or_literal8" do
165173
assert_kind_of Literal, literal_or_literal8("simple\r\n")
166174
assert_kind_of Literal8, literal_or_literal8("has NULL \0")

0 commit comments

Comments
 (0)