Skip to content

Commit b55b945

Browse files
committed
✅ Change FakeServer parse error to IOError on EOF
1 parent 647cc21 commit b55b945

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

test/net/imap/fake_server/command_reader.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
require "net/imap"
44

55
class Net::IMAP::FakeServer
6+
CommandParseError = RuntimeError
67

78
class CommandReader
89
attr_reader :last_command
@@ -22,6 +23,8 @@ def get_command
2223
buf << socket.read(Integer($1))
2324
end
2425
@last_command = parse(buf)
26+
rescue CommandParseError => err
27+
raise IOError, err.message if socket.eof? && !buf.end_with?("\r\n")
2528
end
2629

2730
private
@@ -31,7 +34,7 @@ def get_command
3134
# TODO: convert bad command exception to tagged BAD response, when possible
3235
def parse(buf)
3336
/\A([^ ]+) ((?:UID )?\w+)(?: (.+))?\r\n\z/min =~ buf or
34-
raise "bad request: %p" [buf]
37+
raise CommandParseError, "bad request: %p" [buf]
3538
case $2.upcase
3639
when "LOGIN", "SELECT", "EXAMINE", "ENABLE", "AUTHENTICATE"
3740
Command.new $1, $2, scan_astrings($3), buf

test/net/imap/fake_server/socket.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def initialize(tcp_socket, config:)
1818
def tls?; !!@tls_socket end
1919
def closed?; @closed end
2020

21+
def eof?; socket.eof? end
2122
def gets(...) socket.gets(...) end
2223
def read(...) socket.read(...) end
2324
def print(...) socket.print(...) end

0 commit comments

Comments
 (0)