Skip to content

Return nil, not false, when a line carries no literal - #790

Open
ihamzatarar wants to merge 1 commit into
ruby:masterfrom
ihamzatarar:literal-size-nil-for-long-lines
Open

ihamzatarar wants to merge 1 commit into
ruby:masterfrom
ihamzatarar:literal-size-nil-for-long-lines

Conversation

@ihamzatarar

Copy link
Copy Markdown

Fixes #789.

get_literal_size ends in a && chain, so it returns false rather than nil when the line does not end with a literal prefix:

buff.end_with?("}\r\n") && buff.rindex(/\{(\d+)\}\r\n\z/n) &&
  coerce_number64($1)

read_line assigns that to @literal_size before guard_response_too_large! runs, so when a long line exceeds max_response_size, ResponseTooLargeError#literal_size is false instead of nil. The v0.5 and v0.4 branches are not affected, because there the error is raised before the assignment.

Nothing else changes: done? and min_response_remaining both treat false and nil alike, and response_size_msg already treats false as falsy, so only the attribute value differs. That matches the literal_size: nil default on ResponseTooLargeError#initialize.

The guard is the one @znz suggested on the issue.

Tests

One test in test/net/imap/test_response_reader.rb, covering both halves: an oversized line reports no literal size, and an oversized literal still reports 200. It fails on master with <false> was expected to be nil.

Suite on Ruby 3.4.6, run standalone:

1747 tests, 16957 assertions, 0 failures, 0 errors

test/net/imap/test_stringprep_tables.rb is excluded from that run because it needs rfcs/rfc3454-stringprep_tables.json, which is generated by a rake task rather than checked in. It does not touch this code.

get_literal_size ends in a && chain, so it returned false rather than
nil when the line does not end with a literal prefix. read_line stores
that in @literal_size before guard_response_too_large! runs, so a line
that exceeded max_response_size produced a ResponseTooLargeError whose
literal_size was false instead of nil.

Nothing else changes: done? and min_response_remaining treat false and
nil alike, and response_size_msg already treats false as falsy, so only
the attribute value differs.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ResponseTooLargeError#literal_size is false (not nil) when a line exceeds max_response_size

1 participant