fix(nntp): support open-ended OVER/XOVER ranges ("n-")#66
Closed
johnanleitner1-Coder wants to merge 1 commit into
Closed
fix(nntp): support open-ended OVER/XOVER ranges ("n-")#66johnanleitner1-Coder wants to merge 1 commit into
johnanleitner1-Coder wants to merge 1 commit into
Conversation
parseRange treated a range of the form "low-" (low article to the highest available) as malformed and returned an empty (0,0) range, so OVER/XOVER "n-" returned no articles instead of every article >= n. RFC 3977 defines a range as a single number, "number-", or "number-number"; the open-ended form is common in real NNTP clients. Handle "low-" as (low, MaxInt64), reject specs with more than one dash (e.g. "1-2-3") as malformed, and keep existing malformed handling so a bad range still yields an empty range rather than "all articles". Adds tests for closed, open-ended, empty, and malformed specs. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #65.
Problem
parseRangerejected the open-ended rangelow-(e.g.OVER 5-) as malformed, returning an empty(0, 0)range. SoOVER/XOVERwith a trailing-dash range returned no articles instead of all articles>= low.RFC 3977 ranges come in three forms:
number,number-(open-ended, through the highest article), andnumber-number. The earlier "reject malformed OVER ranges" hardening (#45/#46) accidentally swept up the validnumber-form along with the genuinely malformed ones.Fix
low-now returns(low, math.MaxInt64)— unbounded upper.1-2-3) are rejected as malformed.(0, 0)range (never "all articles"), preserving the NNTP OVER accepts malformed ranges as broad article queries #45/fix(nntp): reject malformed overview ranges #46 hardening.Tests
Extended
range_test.gowith cases for closed (5-10), open-ended (5-), empty (""= all), and malformed (abc,5-abc,abc-5,1-2-3,-,-5) specs.Note on verification
I don't have a Go 1.26 toolchain in my environment, so I verified the logic by hand-tracing every test case against the new code rather than running
go test. The change is a small, pure-function edit using only already-imported packages (math,strconv,strings); please run CI /go test ./internal/news/nntpd/to confirm. Happy to adjust if you'd prefer a different shape (e.g. capping the upper bound to the group's real high-water mark insidehandleOverinstead ofMaxInt64).