ldap: encode string before using urlparse.quote() on them (#31273)
quote() only handle byte strings or ASCII only unicode strings with Python3, to be compatible with both python versions the best is to encode string before quoting them.
This commit is contained in:
parent
0f0c0790d0
commit
b475f6b7df
|
@ -977,20 +977,19 @@ class LDAPBackend(object):
|
|||
'''Build the exernal id for the user, use attribute that eventually
|
||||
never change like GUID or UUID.
|
||||
'''
|
||||
l = []
|
||||
parts = []
|
||||
for attribute in external_id_tuple:
|
||||
quote = True
|
||||
if ':' in attribute:
|
||||
attribute, param = attribute.split(':')
|
||||
quote = 'noquote' not in param.split(',')
|
||||
v = attributes[attribute]
|
||||
if isinstance(v, list):
|
||||
v = v[0]
|
||||
v = force_text(v)
|
||||
part = attributes[attribute]
|
||||
if isinstance(part, list):
|
||||
part = part[0]
|
||||
if quote:
|
||||
v = urlparse.quote(v)
|
||||
l.append(v)
|
||||
return ' '.join(v for v in l)
|
||||
part = urlparse.quote(part.encode('utf-8'))
|
||||
parts.append(part)
|
||||
return ' '.join(part for part in parts)
|
||||
|
||||
def lookup_by_username(self, username):
|
||||
User = get_user_model()
|
||||
|
|
Loading…
Reference in New Issue