`test_file` failed on Windows with a longer repo path in `test_urllib2`
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Python
- Star
- 77.2k
- Fork
- 35.9k
- Chỉ số merge pull request
- Chỉ số pull request đang chờ
Mô tả
On Windows, when the CPython repository is cloned to a slightly longer path, for example, C:\Users\xxxxx\Source\cpython — this test case will fail:
ERROR: test_file (test.test_urllib2.HandlerTests.test_file)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Users\xxxxx\Source\cpython\Lib\encodings\idna.py", line 219, in encode
result.extend(ToASCII(label))
~~~~~~~^^^^^^^
File "C:\Users\xxxxx\Source\cpython\Lib\encodings\idna.py", line 115, in ToASCII
raise UnicodeEncodeError("idna", label, 0, len(label), "label too long")
UnicodeEncodeError: 'idna' codec can't encode characters in position 0-64: label too long
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\xxxxx\Source\cpython\Lib\test\test_urllib2.py", line 872, in test_file
self.assertRaises(urllib.error.URLError,
~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
h.file_open, Request(url))
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\xxxxx\Source\cpython\Lib\unittest\case.py", line 813, in assertRaises
return context.handle('assertRaises', args, kwargs)
~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\xxxxx\Source\cpython\Lib\unittest\case.py", line 247, in handle
callable_obj(*args, **kwargs)
~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
File "C:\Users\xxxxx\Source\cpython\Lib\urllib\request.py", line 1469, in open_local_file
localfile = url2pathname(req.full_url, require_scheme=True)
File "C:\Users\xxxxx\Source\cpython\Lib\urllib\request.py", line 1658, in url2pathname
if not _is_local_authority(authority):
~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^
File "C:\Users\xxxxx\Source\cpython\Lib\urllib\request.py", line 1498, in _is_local_authority
address = socket.gethostbyname(authority)
File "C:\Users\xxxxx\Source\cpython\Lib\encodings\idna.py", line 222, in encode
raise UnicodeEncodeError(
...<5 lines>...
)
UnicodeEncodeError: 'idna' codec can't encode characters in position 8-72: label too long
encoding with 'idna' codec failed
These two URLs will become:
file://127.0.0.1:80C:\Users\xxxxx\Source\cpython\build\test_python_worker_17208æ/@test_17208_tmpæfile://somerandomhost.ontheinternet.comC:\Users\xxxxx\Source\cpython\build\test_python_worker_4676æ/@test_4676_tmpæ
Here, 127.0.0.1:80C:\Users\xxxxx\Source\cpython\build\test_python_worker_17208æ is treated as the domain and passed to socket.gethostbyname. However, the part 1:80C:\Users\xxxxx\Source\cpython\build\test_python_worker_17208æ is too long to be a valid domain label. As a result, the idna codec raises an exception, indicating the label is too long.
A patch is on the way.
Linked PRs
- gh-133449
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu trong Lib/test/test_urllib2.py, tại khu vực quanh test_file, đặc biệt là phần thiết lập URL gần các dòng 857-860 và assertion gần dòng 872. Chạy test.test_urllib2.HandlerTests.test_file trên Windows với đường dẫn checkout dài hơn và so sánh URL cùng exception thu được. Hoàn tất khi test không còn thất bại trong môi trường đó mà vẫn giữ assertion URLError như dự định.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- python
- Lĩnh vực
- testing-qa
- Loại issue
- Lỗi
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức phù hợp với người mới
- 15/100