Repository navigation
Return nil, not false, when a line carries no literal - #790
ihamzatarar wants to merge 1 commit into
Conversation
nevans
left a comment
There was a problem hiding this comment.
The actual fix looks good, with just a few nitpicks around the comments and test.
Also, this PR smells like it was substantially generated. If so, please add something about that to the commit message, such as an Assisted-by: trailer.
Thanks!
| def get_literal_size(buff) | ||
| buff.end_with?("}\r\n") && buff.rindex(/\{(\d+)\}\r\n\z/n) && | ||
| coerce_number64($1) | ||
| # Returning nil rather than false keeps ResponseTooLargeError#literal_size |
There was a problem hiding this comment.
The comment is superfluous, IMO. No justification is needed here.
| client = FakeClient.new | ||
| client.config.max_response_size = 10 | ||
|
|
||
| # The line is what exceeds the limit, so there is no literal size to report. |
There was a problem hiding this comment.
This comment isn't so bad. But it feels slightly redundant, with the test name just a few lines above it. And, IMO, the variable name and assertions below already make it fairly obvious too.
If you think the comment is worth keeping, maybe split this into two tests instead?
| end | ||
| end | ||
|
|
||
| test "#read_response_buffer literal_size is only set by an oversized literal" do |
There was a problem hiding this comment.
literal_sizedoesn't belong toResponseReader.- setting it to
nilis (arguably) still setting it.
So this would be more clear and accurate, IMO:
| test "#read_response_buffer literal_size is only set by an oversized literal" do | |
| test "#read_response_buffer sets ResponseTooLargeError#literal_size" do |
Splitting it into two tests would also be fine, but I don't think that's necessary.
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. Assisted-by: Claude Code <noreply@anthropic.com>
56d6b1e to
81d5af9
Compare
|
Thanks, all applied. I kept it as one test rather than splitting it, since both halves share the And yes, it was. I have added an |
Fixes #789.
get_literal_sizeends in a&&chain, so it returnsfalserather thannilwhen the line does not end with a literal prefix:read_lineassigns that to@literal_sizebeforeguard_response_too_large!runs, so when a long line exceedsmax_response_size,ResponseTooLargeError#literal_sizeisfalseinstead ofnil. The v0.5 and v0.4 branches are not affected, because there the error is raised before the assignment.Nothing else changes:
done?andmin_response_remainingboth treatfalseandnilalike, andresponse_size_msgalready treatsfalseas falsy, so only the attribute value differs. That matches theliteral_size: nildefault onResponseTooLargeError#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:
test/net/imap/test_stringprep_tables.rbis excluded from that run because it needsrfcs/rfc3454-stringprep_tables.json, which is generated by a rake task rather than checked in. It does not touch this code.Assisted-by: Claude Code