Skip to content

Commit 69bd2e4

Browse files
authored
🔀 Merge pull request #605 from ruby/parser/resp_text-backtrack-should-return-ResponseText
🐛 Return ResponseText from `resp-text` fallback
2 parents 3dccb99 + 78c204d commit 69bd2e4

2 files changed

Lines changed: 17 additions & 18 deletions

File tree

lib/net/imap/response_parser.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1888,17 +1888,17 @@ def text?
18881888
# We leniently re-interpret this as
18891889
# resp-text = ["[" resp-text-code "]" [SP [text]] / [text]
18901890
def resp_text
1891-
state = current_state
1892-
if lbra?
1893-
code = resp_text_code; rbra
1894-
ResponseText.new(code, SP? && text? || "")
1895-
else
1896-
ResponseText.new(nil, text? || "")
1891+
begin
1892+
state = current_state
1893+
if lbra?
1894+
code = resp_text_code; rbra
1895+
return ResponseText.new(code, SP? && text? || "")
1896+
end
1897+
rescue ResponseParseError => error
1898+
raise if /\buid-set\b/i.match? error.message
1899+
restore_state state
18971900
end
1898-
rescue ResponseParseError => error
1899-
raise if /\buid-set\b/i.match? error.message
1900-
restore_state state
1901-
text
1901+
ResponseText.new(nil, text? || "")
19021902
end
19031903

19041904
# RFC3501 (See https://www.rfc-editor.org/errata/rfc3501):

test/net/imap/fixtures/response_parser/quirky_behaviors.yml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,20 @@
3737
3838
Microsoft Exchange is issuing an invalid resp-text-code, but net-imap
3939
should fallback to `resp-text = text` when resp-text-code fails to parse.
40-
:debug: false # current version of backtracking still prints parse_errors
4140
:response: "RUBY0001 OK [Error=\"Microsoft.Exchange.Data.Storage.WrongServerException:
4241
Cross Server access is not allowed for mailbox xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\"
4342
AuthResultFromPopImapEnd=0 Proxy=XXXXXXXXXXXXX.EURXXXX.PROD.OUTLOOK.COM:1993:SSL
4443
MailboxBE=XXXXXXXXXXXXX.EURXXXX.PROD.OUTLOOK.COM
4544
Service=Imap4] AUTHENTICATE completed.\r\n"
4645
:expected: !ruby/struct:Net::IMAP::TaggedResponse
47-
tag: RUBY0001
46+
tag: RUBY0001
4847
name: OK
49-
data: '[Error="Microsoft.Exchange.Data.Storage.WrongServerException: Cross Server
50-
access is not allowed for mailbox xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
51-
AuthResultFromPopImapEnd=0
52-
Proxy=XXXXXXXXXXXXX.EURXXXX.PROD.OUTLOOK.COM:1993:SSL
53-
MailboxBE=XXXXXXXXXXXXX.EURXXXX.PROD.OUTLOOK.COM Service=Imap4]
54-
AUTHENTICATE completed.'
48+
data: !ruby/struct:Net::IMAP::ResponseText
49+
code:
50+
text: '[Error="Microsoft.Exchange.Data.Storage.WrongServerException: Cross Server
51+
access is not allowed for mailbox xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" AuthResultFromPopImapEnd=0
52+
Proxy=XXXXXXXXXXXXX.EURXXXX.PROD.OUTLOOK.COM:1993:SSL MailboxBE=XXXXXXXXXXXXX.EURXXXX.PROD.OUTLOOK.COM
53+
Service=Imap4] AUTHENTICATE completed.'
5554
raw_data: "RUBY0001 OK [Error=\"Microsoft.Exchange.Data.Storage.WrongServerException:
5655
Cross Server access is not allowed for mailbox xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\"
5756
AuthResultFromPopImapEnd=0 Proxy=XXXXXXXXXXXXX.EURXXXX.PROD.OUTLOOK.COM:1993:SSL

0 commit comments

Comments
 (0)