Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/net/imap/command_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions test/net/imap/test_command_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down