apache / apache/libcloud

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

Aperta
#1,452 6 commenti 0 reazioni 0 assegnatari Vedi su GitHub
api: http layer potential 2.8.x candidate python 2.x and 3.x compatibility stale
Lingua principale
Python
Stelle
2.1k
Fork
931
Merge medio
1g 2h
PR unite (30g)
4

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Iniziare in utils/py3.py dall'utility urlquote() e confrontarne il comportamento in Python 2 con Python 3 e RFC 3986. Il lavoro è completato quando i caratteri tilde rimangono non codificati in modo coerente in entrambe le versioni di Python, incluso il caso Amazon S3 descritto nell'issue.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
backend
Tipo di issue
Bug
Difficoltà
2/5
Tempo stimato
1-3 ore
Stato di attività
Ferma
Chiarezza
Specificata chiaramente
Idoneità per principianti
45/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.