Repository navigation
Conversation
Allow zero-digit ports in PORT_RE per RFC 3986 section 3.2.3 and normalize empty port matches to None in URIMixin.authority_info() so normalize() omits the colon without dropping the host.
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.
Problem
PORT_REinsrc/rfc3986/abnf_regexp.pyis defined as"[0-9]{1,5}", whereas RFC 3986 §3.2.3 definesport = *DIGIT(zero or more digits) and §6.2.3 states that URI producers and normalizers should omit the":"delimiter when the port is empty.Because an empty port such as
HTTP://example.com:/afailsSUBAUTHORITY_MATCHER,authority_info()raisesInvalidAuthority.URIReference.normalize()catchesInvalidAuthorityvianormalize_authority()and drops the authority components, silently rewritingHTTP://example.com:/ato"http:/a"and erasing the hostname.Fix
PORT_REinsrc/rfc3986/abnf_regexp.pyfrom"[0-9]{1,5}"to"[0-9]{0,5}"so authorities with an empty port matchSUBAUTHORITY_MATCHER."port"("") toNoneinURIMixin.authority_info()(src/rfc3986/_mixin.py), preserving existinguri.port is Nonesemantics (includingtest_handles_colon_but_no_port) while keepinghostanduserinfointact sonormalize().unsplit()produces"http://example.com/a".test_empty_port_preserves_host_on_normalize) intests/test_uri.pycovering reg-name, userinfo + dot-segment path, and IPv6 literal hosts with empty ports.Verification
test_empty_port_preserves_host_on_normalizefails before the fix ("http:/a") and passes after.pytest --cov rfc3986 --cov-fail-under 100 tests/.line-length = 79) and lint checks cleanly on all modified files.