Repository navigation
Reject unparseable IRI authorities before encoding - #169
Open
anishpentyala wants to merge 2 commits into
Open
anishpentyala wants to merge 2 commits into
anishpentyala wants to merge 2 commits into
Conversation
Preserve malformed nonempty authorities as InvalidAuthority rather than silently erasing them during encode. Source independently reviewed at bc90e68a6a8acf1f483359455c0ddf12224976da.
Preserve malformed nonempty authorities as InvalidAuthority rather than silently erasing them during encode. Source independently reviewed at bc90e68a6a8acf1f483359455c0ddf12224976da.
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.
IRIReference.encode()currently rebuilds an authority through thehost,userinfo, andportconvenience properties. Those properties suppressInvalidAuthorityand returnNonewhen the existing authority parser cannot parse the authority. Encoding then silently drops the authority:This calls
authority_info()before rebuilding so an unparseable, nonempty authority raises the existingInvalidAuthorityexception instead. Existing property dispatch, custom IDNA encoder behavior, missing-dependency precedence, and successful encodings are preserved.Tests add 16 regression cases covering malformed ports, whitespace, malformed IPv6, invalid IPv4, and an invalid host character, each with the default and a custom encoder. Thirteen control cases cover valid credentials, IPv6/zone IDs, absent hosts/authorities, and the existing empty-port normalization. Against the unchanged base, all 16 regressions fail and all 13 controls pass.
Validation on CPython 3.10.12 and 3.13.17:
Scope and tradeoffs: this follows the existing authority parser, not a new claim of full RFC validity. For example, the parser currently rejects empty userinfo (
@example.com), even though that form is allowed by the RFC; this change raises instead of silently discarding it. Existing empty-port stripping and numeric port-range behavior are unchanged. The extra parse measured about 1-1.5 microseconds per credential-bearing encode locally (roughly 4-8% overhead), so this is not throughput-neutral. No unrelated normalization or validation behavior is changed.