Repository navigation
fix(ftp): reject arguments that are not str, bytes or bytearray (#2410) - #2414
Merged
Merged
Conversation
FTP.make's args branch encoded anything that was not bytes, so a bytearray,
int, bool or memoryview raised a bare AttributeError ('bytearray' object has
no attribute 'encode') instead of a ProtocolError. The gap predates #2365,
which widened the sibling cmmd parameter but left args as it was.
Accept a bytes or bytearray verbatim, encode only a genuine str, and raise
"FTP: invalid arguments: must be a str, bytes or bytearray, not ..." for
anything else, mirroring cmmd's guard from #2365. Widened the args annotation
to include bytearray and extended the Args:/Raises: docstring entries.
Test: tests/protocols/application/test_ftp_unit.py gains
test_ftp_make_rejects_arguments_that_are_not_str_bytes_or_bytearray, pinning
the exact message for int, bool, float, memoryview and a .value-carrying
object, and a bytearray argument building on both a request and a reply.
Confirmed fail-without-fix: with the guard reverted the test fails 6/6 with
AttributeError rather than ProtocolError.
tests/protocols/ in full: 2021 passed / 51393 subtests / 0 failed, after
regenerating examples/captures via examples/generators/make_samples.py. mypy
reports nothing on ftp.py and pylint's findings on both touched files are
unchanged from main.
Contributor
|
Coverage: 91.72% (unit tier, Python 3.15,
Per-file detail: the |
Owner
Author
|
Review: GOOD TO GO at |
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.
Please follow the guide below
make pylint,make mypy,make isort)make testpasses, and a test case covers the changedocs/source/changelog/and regeneratedCHANGELOG.md, if the change is user-visible — N/A, centralised in docs(changelog): shared 1.5.0 changelog — long-lived, merges last (#610, #616, #617, #618, #620) #657What is the purpose of your pull request?
fix— corrects a defectfeat— adds a featureperf— changes performance, not behaviourrefactor— changes neither behaviour nor performancetest— tests onlydocs— documentation onlyci— workflows or build toolingrelease— bumps the version or rolls up a distributionchore— anything elseDescription of your pull request and other information
Fixes #2410.
FTP.make'sargsbranch encoded anything that was notbytes, soFTP(cmmd='USER', args=bytearray(b'anonymous'))raisedAttributeError: 'bytearray' object has no attribute 'encode';args=42,args=Trueandargs=memoryview(b'x')failed the same way. The gap predates #2365, which widened the siblingcmmdparameter and leftargsas it was.The branch now takes a
bytesorbytearrayverbatim, encodes only a genuinestr, and raisesFTP: invalid arguments: must be a str, bytes or bytearray, not ...for anything else — the same shape ascmmd's guard from #2365. Theargsannotation gainsbytearray, and theArgs:/Raises:entries onmakedocument it.Fail-without-fix: with the guard reverted to
elif isinstance(args, bytes), the new test fails 6/6 (5 subtests plus the bytearray acceptance), each withAttributeError: '<type>' object has no attribute 'encode'rather than the expectedProtocolError.Tests:
tests/protocols/in full — 2021 passed / 51393 subtests / 0 failed, after regeneratingexamples/captureswithexamples/generators/make_samples.py. mypy reports nothing onftp.py; pylint's findings on both touched files are unchanged frommain.