fix: port property leaks stale scheme default when scheme changes#191
Open
gaoflow wants to merge 1 commit into
Open
fix: port property leaks stale scheme default when scheme changes#191gaoflow wants to merge 1 commit into
gaoflow wants to merge 1 commit into
Conversation
…n scheme change The port setter stored DEFAULT_PORTS.get(self.scheme) in self._port when port=None was passed. This cached the scheme-dependent default port, which then became stale when the scheme later changed — the port property returned the cached value instead of the new scheme's default. Concrete bug (issue gruns#143): set(scheme=None, netloc=None) on an https URL produced '//:443/hello' instead of '/hello', because netloc=None set _port=443 (the https default) before scheme=None cleared the scheme. Fix: store None in _port when port=None, letting the port getter's existing logic supply the scheme-appropriate default dynamically. Also removes the now-unnecessary _port cache assignment in load().
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.
The port setter stores
DEFAULT_PORTS.get(self.scheme)inself._portwhenport=None. This caches the scheme-dependent default port, which becomes stale when the scheme later changes -- the port property returns the cached value instead of the new scheme's default.Concrete reproduction:
Root cause:
netloc=Noneprocesses beforescheme=Noneinset(), soport=NonecachesDEFAULT_PORTS['https']=443before the scheme is cleared.Fix: store
Nonein_portwhenport=None, letting the port getter's existingself._port or DEFAULT_PORTS.get(self.scheme)logic supply the scheme-appropriate default dynamically at access time. This also fixes the case whereport=Nonefollowed byscheme='https'previously returned port 80 instead of 443.Also removes the now-unnecessary
_portcache assignment inload().Fixes #143.