Repository navigation
fix(ftp,httpv1): FTP and HTTP/1 lines do not rebuild byte for byte - #1301
Merged
Merged
Conversation
- FTP `make` ends every line with CRLF (#1238). - A line with no arguments parses with `args=None`, and `make` writes no separator for it (#1239). - A multi-line reply's text follows the hyphen immediately, per RFC 959 section 4.2; only one SP is syntax elsewhere, the rest is argument (#1240). - Text whose decoding does not encode back as UTF-8 records its charset in a new `charset` field on the FTP request/response and HTTP/1 start-line data, and `make` takes `charset` to re-encode with it (#1241). - The FTP regexes anchor with `\Z`, so a trailing `\n` is no longer dropped.
This was referenced Oct 7, 2026
Closed
Contributor
|
Coverage: 88.90% (unit tier, Python 3.14,
Per-file detail: the |
Owner
Author
|
Cross-review verdict on
|
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.
make pylint,make mypy,make isort) — ran pylint/mypy/isort on the touched files: no new findings (httpv1.py's isort complaint and the existing pylint design warnings predate this)make testpasses, and a test case covers the change — modules listed below, not the full suiteWhat is the purpose of your pull request?
fix— corrects a defectDescription
Closes #1238
Closes #1239
Closes #1240
Closes #1241
FTP
makeappends CRLF, omits the separator whenargs is Noneand after a reply hyphen (RFC 959 §4.2). Only the single SP is syntax, soUSER x,220- xandQUITkeep their bytes.\Zreplaces$. For #1241, text that would not re-encode as UTF-8 records the detected charset (orlatin-1as a fallback).protocol.py's chardet decoding is unchanged, and the displayedstris the same as before.Breaking: FTP
Request/Responseand HTTP/1RequestHeader/ResponseHeaderhave a new requiredcharsetfield. FTPargsisNonefor argument-less lines.220- Readynow parses toargs=' Ready', which updates the existing pin intest_ftp_unit.py.makealso acceptscharset.Probe: before the fix,
USER anonymous\r\nraises ProtocolError,QUIT\r\nraises TypeError,220-Welcome\r\nraises ProtocolError, andGET /caf\xe9rebuilds as/caf\xc3\xa9. After it, all of them plus the latin-1 FTP and HTTP reason phrase rebuild byte-exactly. All 241 HTTP layers inexamples/captures/*round-trip, both before and after.Tests:
test_ftp_http1_roundtrip_unitpasses 8/8 with 16 subtests; with the fix reverted, 5 tests and 15 subtests fail (only the UTF-8 HTTP control passes).test_ftp_unit10,test_http_unit65,test_http_runtime5,test_http_from_data_11544,test_option_roundtrip6,tests/project389 passed. Therun_unittest_leg.py protocols --exclude protocols/internetleg ran 858 tests, OK.Out of scope: HTTP/1 header field values are still re-encoded as UTF-8, and a multi-line FTP reply in one segment still fails to parse.