Tilde ('~') character is incorrectly URL-encoded with Python 2
- Ngôn ngữ chính
- Python
- Star
- 2.1k
- Fork
- 931
- Merge trung bình
- 1 ngày 2 giờ
- Pull request đã merge (30 ngày)
- 4
Mô tả
I'm referring to the older, unresolved issue here (it seems I cannot create a new issue nor comment on the older one over at issues.apache.org though I have a long-time user there...):
https://issues.apache.org/jira/browse/LIBCLOUD-979
I can confirm that the reported issue happens also for Amazon S3, not only for CEPH as originally reported. And the problem is indeed that libcloud URL-encodes the tilde '~' sign to '%7E', which it shouldn't according to RFC 3986.
The problem seems specific to Python 2 because in Python 3 urllib.quote() has been already updated to not URL-encode the tilde '~' sign anymore:
https://bugs.python.org/issue16285
Because of this, I think the correct fix (other than the patch proposed in LIBCLOUD-979) would be adding the tilde '~' character to the safe characters in the urlquote() utility function in utils/py3.py to ensure consistent behavior between Python 2 and Python 3.
```diff
--- libcloud/utils/py3.py 2020-04-30 12:58:55.804591828 +0000
+++ libcloud_fixed/utils/py3.py 2020-04-30 12:59:25.975368813 +0000
@@ -211,7 +211,7 @@
tostring = ET.tostring
- def urlquote(s, safe='/'):
+ def urlquote(s, safe='/~'):
if isinstance(s, _real_unicode):
# Pretend to be py3 by encoding the URI automatically.
s = s.encode('utf8')
```
Hướng dẫn đóng góp
Hướng nghiên cứu
Bắt đầu trong tiện ích urlquote() ở utils/py3.py và so sánh hành vi của nó trên Python 2 với Python 3 và RFC 3986. Công việc hoàn tất khi các ký tự dấu ngã vẫn nhất quán không được mã hóa trên cả hai phiên bản Python, bao gồm cả trường hợp Amazon S3 được mô tả trong issue.
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
- backend
- 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
- 45/100