python / python/cpython

Inconsistent url parsing between urllib.parse and urllib.request with ":@" in netloc

オープン
#98,218 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

stdlib type-bug
主要言語
Python
スター
77.2k
フォーク
36k
PR マージ指標
PR 指標を取得中

説明

Bug report

With "https://host:@1/path", urlib.parse.urlsplit parses "host" as the user and "1" as the hostname with no port.
If I use this url with urllib.request.urlopen, it parses "@1" as being the port.

Python 3.9.6 (default, Jun 28 2021, 08:57:49) 
[GCC 11.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from urllib.parse import urlsplit
>>> s = urlsplit("https://host:@1/path")
>>> s.hostname
'1'
>>> s.port
>>> s.username
'host'
>>> import urllib.request
>>> urllib.request.urlopen(urllib.request.Request("https://host:@1/path"))
Traceback (most recent call last):
  File "/usr/lib/python3.9/http/client.py", line 872, in _get_hostport
ValueError: invalid literal for int() with base 10: '@1'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.9/urllib/request.py", line 214, in urlopen
  File "/usr/lib/python3.9/urllib/request.py", line 517, in open
  File "/usr/lib/python3.9/urllib/request.py", line 534, in _open
  File "/usr/lib/python3.9/urllib/request.py", line 494, in _call_chain
  File "/usr/lib/python3.9/urllib/request.py", line 1389, in https_open
  File "/usr/lib/python3.9/urllib/request.py", line 1315, in do_open
  File "/usr/lib/python3.9/http/client.py", line 1384, in __init__
  File "/usr/lib/python3.9/http/client.py", line 834, in __init__
  File "/usr/lib/python3.9/http/client.py", line 877, in _get_hostport
http.client.InvalidURL: nonnumeric port: '@1'

Your environment

  • CPython versions tested on: 3.9.6
  • Operating system and architecture: Linux

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

urllib.parse.urlsplit と urllib.request.urlopen から始め、その後、traceback に示されている http.client の host/port 処理を追跡します。各経路が https://host:@1/path をどのように解釈するかを比較し、期待される一貫した結果を特定します。報告された parsing mismatch なしに両方の経路が一致し、関連するテストが通れば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
networking
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
45/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。