Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix building the URL in BaseRequest when the host contains a port or IPv6 address #9309

Merged
merged 6 commits into from
Sep 27, 2024

Conversation

bdraco
Copy link
Member

@bdraco bdraco commented Sep 27, 2024

What do these changes do?

The port was incorrectly being passed in the host field to URL.build when the Host header included the port

Are there changes in behavior for the user?

Calling BaseRequest.url will not fail with yarl 1.13.0+ when the host header has a port

Is it a substantial burden for the maintainers to support this?

no

Related issue number

fixes #9307

@bdraco bdraco added backport-3.10 Trigger automatic backporting to the 3.10 release branch by Patchback robot backport-3.11 Trigger automatic backporting to the 3.11 release branch by Patchback robot labels Sep 27, 2024
@bdraco
Copy link
Member Author

bdraco commented Sep 27, 2024

Will need a test as well .. but super late here so I'll have to pickup tomorrow

Copy link

codecov bot commented Sep 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.55%. Comparing base (0b8be7f) to head (0e32a09).
Report is 6 commits behind head on master.

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #9309   +/-   ##
=======================================
  Coverage   98.55%   98.55%           
=======================================
  Files         107      107           
  Lines       34867    34872    +5     
  Branches     4134     4134           
=======================================
+ Hits        34364    34369    +5     
  Misses        335      335           
  Partials      168      168           
Flag Coverage Δ
CI-GHA 98.44% <100.00%> (+<0.01%) ⬆️
OS-Linux 98.11% <100.00%> (+<0.01%) ⬆️
OS-Windows 96.51% <100.00%> (+<0.01%) ⬆️
OS-macOS 97.79% <100.00%> (-0.01%) ⬇️
Py-3.10.11 97.77% <100.00%> (+<0.01%) ⬆️
Py-3.10.15 97.70% <100.00%> (+<0.01%) ⬆️
Py-3.11.10 97.67% <100.00%> (+<0.01%) ⬆️
Py-3.11.9 97.73% <100.00%> (-0.01%) ⬇️
Py-3.12.6 98.16% <100.00%> (+<0.01%) ⬆️
Py-3.13.0-rc.2 98.15% <100.00%> (+<0.01%) ⬆️
Py-3.9.13 97.67% <100.00%> (-0.01%) ⬇️
Py-3.9.20 97.60% <100.00%> (+<0.01%) ⬆️
Py-pypy7.3.16 97.22% <100.00%> (+<0.01%) ⬆️
VM-macos 97.79% <100.00%> (-0.01%) ⬇️
VM-ubuntu 98.11% <100.00%> (+<0.01%) ⬆️
VM-windows 96.51% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

aiohttp/web_request.py Outdated Show resolved Hide resolved
aiohttp/web_request.py Outdated Show resolved Hide resolved
@bdraco
Copy link
Member Author

bdraco commented Sep 27, 2024

It's even more messy because when it's cloned we use the host but host is the raw host in this case. Actually it's even the host subcomponent so calling .host is very inconsistent about what you actually get

... and if it's idna encoding it's probably wrong as well

There aren't any tests for handling IPv6 hosts correctly either

We also probably want to let yarl parse the raw host instead of using URL.build

@bdraco
Copy link
Member Author

bdraco commented Sep 27, 2024

Maybe the simplest fix is to pass it as authority instead of host

@bdraco
Copy link
Member Author

bdraco commented Sep 27, 2024

Maybe the simplest fix is to pass it as authority instead of host

But that's really inefficient because it creates new split results and reparses it 4x

https:/aio-libs/yarl/blob/38ef0f95d25c240e17963971a41ed85b0b0c4e31/yarl/_url.py#L371

Should fix that to use the same logic in new but will need a lot of tests

@psf-chronographer psf-chronographer bot added the bot:chronographer:provided There is a change note present in this PR label Sep 27, 2024
@bdraco bdraco changed the title Fix building the URL in BaseRequest when the host contains a port Fix building the URL in BaseRequest when the host contains a port or IPv6 address Sep 27, 2024
@bdraco
Copy link
Member Author

bdraco commented Sep 27, 2024

New tests fail with the following on master before the fix

FAILED tests/test_web_request.py::test_url_non_default_port - ValueError: Host 'example.com:8123' cannot contain ':' (at position 11)
FAILED tests/test_web_request.py::test_url_ipv6 - ValueError: Host '[::1]:8123' cannot contain '[' (at position 0)

@bdraco bdraco marked this pull request as ready for review September 27, 2024 18:22
@bdraco bdraco merged commit e402833 into master Sep 27, 2024
39 of 40 checks passed
@bdraco bdraco deleted the fix_url branch September 27, 2024 18:23
Copy link
Contributor

patchback bot commented Sep 27, 2024

Backport to 3.10: 💚 backport PR created

✅ Backport PR branch: patchback/backports/3.10/e40283338eab5b501e8e91e5b24c2c38cb1a0c71/pr-9309

Backported as #9318

🤖 @patchback
I'm built with octomachinery and
my source is open — https:/sanitizers/patchback-github-app.

patchback bot pushed a commit that referenced this pull request Sep 27, 2024
Copy link
Contributor

patchback bot commented Sep 27, 2024

Backport to 3.11: 💚 backport PR created

✅ Backport PR branch: patchback/backports/3.11/e40283338eab5b501e8e91e5b24c2c38cb1a0c71/pr-9309

Backported as #9319

🤖 @patchback
I'm built with octomachinery and
my source is open — https:/sanitizers/patchback-github-app.

patchback bot pushed a commit that referenced this pull request Sep 27, 2024
bdraco pushed a commit that referenced this pull request Sep 27, 2024
…t when the host contains a port or IPv6 address (#9319)

Co-authored-by: J. Nick Koston <[email protected]>
fixes #9307
bdraco pushed a commit that referenced this pull request Sep 27, 2024
…t when the host contains a port or IPv6 address (#9318)

Co-authored-by: J. Nick Koston <[email protected]>
fixes #9307
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-3.10 Trigger automatic backporting to the 3.10 release branch by Patchback robot backport-3.11 Trigger automatic backporting to the 3.11 release branch by Patchback robot bot:chronographer:provided There is a change note present in this PR
Projects
None yet
1 participant