Conversation
… literal value qBittorrent uses "all" to mean "no filtering" for both the `filter` and `hashes` query parameters. Both were matched literally, so each returned an empty list: no entry has the state "all", and no torrent has the infohash "all". - handleTorrentsInfo forwarded `filter` straight through as a storage.TorrentState, so `?filter=all` matched nothing. The surrounding strings.Trim(value, "") was also a no-op -- an empty cutset trims nothing, so a padded value was not trimmed either. Normalisation now lives in normalizeStateFilter, which the handler calls, so it is testable directly rather than through a copy of its logic. - ListFilterFunc added every supplied hash to the match set, so `hashes=all` filtered for a torrent whose infohash is the string "all". A lone "all" is now treated as the sentinel; a list containing it stays a literal selection, since a multi-hash request is a genuine choice of torrents. Unrecognised filter values are still passed through verbatim rather than being guessed at, and every other filter continues to apply alongside the sentinel. Both tests fail on the previous behaviour at the described defect and pass with a real state or a real infohash either way, so neither can pass by over-correcting.
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.
What breaks:
GET /api/v2/torrents/info?filter=allreturns[], even when torrents exist. Same forhashes=all.Why: qBittorrent uses
allto mean no filtering for both parameters, and both are matched literally.handleTorrentsInfoforwardsfilterstraight through as astorage.TorrentState, soListFilterFuncevaluatest.State != "all"— true for every entry, so nothing matches. (The neighbouringstrings.Trim(value, "")is also a no-op: an empty cutset trims nothing, so a padded value isn't trimmed either.)ListFilterFuncadds every supplied hash to the match set, sohashes=allfilters for a torrent whose infohash is the literal stringall.allis the qBittorrent default, so any client that sends it explicitly sees an empty queue rather than an error — which reads as "nothing is downloading" rather than as a bug.The fix: treat the sentinel as unfiltered in both places.
Normalisation moved into
normalizeStateFilter, which the handler calls, so the behaviour is tested through the production path rather than through a copy of the logic in a test file. Forhashes, only a loneallis the sentinel — a list containing it stays a literal selection, since a multi-hash request is a genuine choice of torrents. Unrecognised filter values are still passed through verbatim rather than guessed at, and every other filter still applies alongside the sentinel.Evidence: running in production on a ~47,000-entry library, where this was found while diagnosing an unrelated issue: a same-instant census showed
/api/torrentsreturning 117 rows while?filter=allreturned 0.Both tests fail on the current behaviour at the described defect, and the "a real state" / "a real infohash" cases pass with and without the change, so neither can pass by over-correcting.