apache / apache/libcloud

Tilde ('~') character is incorrectly URL-encoded with Python 2

オープン
#1,452 コメント 6 件 リアクション 0 件 担当者 0 名 GitHub で見る
api: http layer potential 2.8.x candidate python 2.x and 3.x compatibility stale
主要言語
Python
スター
2.1k
フォーク
931
平均マージ
1日 2時間
マージ済み PR(30日)
4

説明

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')
```

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

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

調査の方向性

utils/py3.py の urlquote() ユーティリティから始め、Python 2 での動作を Python 3 および RFC 3986 と比較します。両方の Python バージョンでチルダ文字が一貫してエンコードされずに残り、Issue で説明されている Amazon S3 のケースも含まれれば、作業は完了です。

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

評価

技術スタック
python
領域
backend
issue の種類
バグ
難易度
2/5
見積もり時間
1〜3時間
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
45/100

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

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