`urllib.parse.parse_qsl` is accepting illegal characters
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ả
Bug report
Bug description:
urllib.parse.parse_qsl parses query strings containing the ^ and ` characters, even though these are not valid query characters under RFC 3986.
Observed behaviour:
parse_qsl('foo=^', strict_parsing=True)
# [('foo', '^')]
parse_qsl('bar=`', strict_parsing=True)
# [('bar', '`')]
Expected behaviour:
According to RFC 3986, both ^ and ` must be percent-encoded if used in a URI. However, parse_qsl accepts them as-is without raising an error or warning. This could lead to applications treating invalid URLs as valid.
Detailed Code:
import sys
import platform
from urllib.parse import parse_qsl
def test_parse_qsl(query):
try:
result = parse_qsl(query, strict_parsing=True)
print(f"Query: {query!r} -> Parsed: {result}")
except ValueError as e:
print(f"Query: {query!r} -> Error: {e}")
# Test invalid query strings
test_parse_qsl("foo=^")
test_parse_qsl("bar=`")
# System information
os_name = platform.system()
os_release = platform.release()
python_impl = platform.python_implementation()
python_version = sys.version.split()[0]
python_compiler = platform.python_compiler()
print("\n--- System Information ---")
print(f"Python Implementation : {python_impl}")
print(f"Python Version : {python_version}")
print(f"Python Compiler : {python_compiler}")
print(f"Operating System : {os_name} {os_release}")
print(f"Machine : {platform.machine()}")
# Output:
# Query: 'foo=^' -> Parsed: [('foo', '^')]
# Query: 'bar=`' -> Parsed: [('bar', '`')]
# --- System Information ---
# Python Implementation : CPython
# Python Version : 3.13.1
# Python Compiler : GCC 14.2.0
# Operating System : Linux 4.14.174
# Machine : x86_64
References:
-
Section 2.2 Reserved Characters: https://datatracker.ietf.org/doc/html/rfc3986#section-2.2
-
Section 2.3 Unreserved Characters: https://datatracker.ietf.org/doc/html/rfc3986#section-2.3
CPython versions tested on:
3.13
Operating systems tested on:
Linux
Linked PRs
- gh-138291
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 từ entry point urllib.parse.parse_qsl và so sánh hành vi hiện tại của nó với các mục 2.2 và 2.3 của RFC 3986. Xem lại các bài kiểm thử urllib.parse hiện có, sau đó xác minh rằng các query chứa ^ và ` chưa được mã hóa được xử lý theo đặc tả và rằng phạm vi kiểm thử hồi quy ghi nhận hành vi mong đợi.
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
- networking
- Loại issue
- Lỗi
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- 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
- 25/100