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

Add test coverage for handling port 0 #1182

Merged
merged 2 commits into from
Oct 10, 2024
Merged

Add test coverage for handling port 0 #1182

merged 2 commits into from
Oct 10, 2024

Conversation

bdraco
Copy link
Member

@bdraco bdraco commented Oct 8, 2024

What do these changes do?

This was wrong in previous yarl releases, but fixed by one of the cleanups in 1.14.0. Add coverage to make sure it continues to work as 0 is not a default port

The problem:

str(URL("http://example.com:0/")) should be http://example.com:0/ because 0 is not the default port for http

yarl 1.9.5 - 1.13.1 produced it as http://example.com/

bdraco added 2 commits October 8, 2024 12:38
This was wrong in previous yarl releases, but fixed by one
of the cleanups in 1.14.0. Add coverage to make sure it
continutes to work as 0 is not a default port
This was wrong in previous yarl releases, but fixed by one
of the cleanups in 1.14.0. Add coverage to make sure it
continutes to work as 0 is not a default port
@webknjaz
Copy link
Member

webknjaz commented Oct 8, 2024

Isn't 0 only used as an ephemeral port that is resolved to something else by the kernel?

@webknjaz
Copy link
Member

webknjaz commented Oct 8, 2024

What was the fix, by the way?

Copy link

codecov bot commented Oct 8, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.58%. Comparing base (5a4f23d) to head (8341a59).
Report is 243 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1182   +/-   ##
=======================================
  Coverage   95.57%   95.58%           
=======================================
  Files          25       25           
  Lines        4864     4871    +7     
  Branches      443      443           
=======================================
+ Hits         4649     4656    +7     
  Misses        189      189           
  Partials       26       26           
Flag Coverage Δ
CI-GHA 95.56% <100.00%> (+<0.01%) ⬆️
MyPy 42.22% <0.00%> (-0.07%) ⬇️
OS-Linux 99.40% <100.00%> (+<0.01%) ⬆️
OS-Windows 99.47% <100.00%> (+<0.01%) ⬆️
OS-macOS 99.09% <100.00%> (+<0.01%) ⬆️
Py-3.10.11 98.99% <100.00%> (+<0.01%) ⬆️
Py-3.10.15 99.27% <100.00%> (+<0.01%) ⬆️
Py-3.11.10 99.27% <100.00%> (+<0.01%) ⬆️
Py-3.11.9 98.99% <100.00%> (+<0.01%) ⬆️
Py-3.12.6 98.99% <100.00%> (-0.29%) ⬇️
Py-3.12.7 99.27% <100.00%> (-0.01%) ⬇️
Py-3.13.0-rc.3 99.27% <100.00%> (+<0.01%) ⬆️
Py-3.8.10 98.94% <100.00%> (+<0.01%) ⬆️
Py-3.8.18 99.22% <100.00%> (+<0.01%) ⬆️
Py-3.9.13 98.94% <100.00%> (+<0.01%) ⬆️
Py-3.9.20 99.22% <100.00%> (+<0.01%) ⬆️
Py-pypy7.3.11 99.28% <100.00%> (+<0.01%) ⬆️
Py-pypy7.3.16 99.28% <100.00%> (+<0.01%) ⬆️
Py-pypy7.3.17 99.31% <100.00%> (+<0.01%) ⬆️
VM-macos-latest 99.09% <100.00%> (+<0.01%) ⬆️
VM-ubuntu-latest 99.40% <100.00%> (+<0.01%) ⬆️
VM-windows-latest 99.47% <100.00%> (+<0.01%) ⬆️
pytest 99.40% <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.

@bdraco
Copy link
Member Author

bdraco commented Oct 8, 2024

Isn't 0 only used as an ephemeral port that is resolved to something else by the kernel?

I don't expect anyone is using it in production, and this likely only affects downstream tests

@bdraco
Copy link
Member Author

bdraco commented Oct 8, 2024

What was the fix, by the way?

I need to go back and figure out which PR fixed it. Its likely a None check that was corrected

@webknjaz
Copy link
Member

webknjaz commented Oct 8, 2024

I was under impression that using this port in URLs isn't even legal since it doesn't have defined semantics, I think 🤔

@bdraco
Copy link
Member Author

bdraco commented Oct 8, 2024

I was under impression that using this port in URLs isn't even legal since it doesn't have defined semantics, I think 🤔

urllib seems to allow it and it does specifically check the port is between 0 and 65535

>>> from urllib.parse import urlparse
>>> urlparse("http://example.com:0")
ParseResult(scheme='http', netloc='example.com:0', path='', params='', query='', fragment='')
>>> urlparse("http://example.com:0").port
0
>>> 
>>> urlparse("http://example.com:70000").port
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/homebrew/Cellar/[email protected]/3.12.4/Frameworks/Python.framework/Versions/3.12/lib/python3.12/urllib/parse.py", line 184, in port
    raise ValueError("Port out of range 0-65535")
ValueError: Port out of range 0-65535

@bdraco
Copy link
Member Author

bdraco commented Oct 8, 2024

was fixed in #1170 79d53eb

@bdraco bdraco added the bot:chronographer:skip This PR does not need to include a change note label Oct 8, 2024
@webknjaz
Copy link
Member

webknjaz commented Oct 8, 2024

Ack. Though, I wonder what the use-case for this is.

@bdraco
Copy link
Member Author

bdraco commented Oct 8, 2024

I'm not sure there is one. I only noticed because of downstream tests, but none of them actually use 0 in production.

@bdraco
Copy link
Member Author

bdraco commented Oct 8, 2024

It looks like it originally regressed in https://github.com/aio-libs/yarl/releases/tag/v1.9.5. I'm guessing #1033

@webknjaz
Copy link
Member

webknjaz commented Oct 8, 2024

Perhaps it's useful in the context of non-HTTP URLs. Like those used with custom handlers in mobile apps and so on..

@bdraco
Copy link
Member Author

bdraco commented Oct 10, 2024

I'm sure someone is using it for something somewhere so its good to have coverage we don't regress it again.

@bdraco bdraco merged commit fe96599 into master Oct 10, 2024
47 of 49 checks passed
@bdraco bdraco deleted the port_zero branch October 10, 2024 18:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bot:chronographer:skip This PR does not need to include a change note
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants