From b475f6b7dff30d0bd20c60eedc8542f05e51256f Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Mon, 11 Mar 2019 20:48:27 +0100 Subject: [PATCH 4/5] 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. --- src/authentic2/backends/ldap_backend.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/authentic2/backends/ldap_backend.py b/src/authentic2/backends/ldap_backend.py index 11131358..dc084407 100644 --- a/src/authentic2/backends/ldap_backend.py +++ b/src/authentic2/backends/ldap_backend.py @@ -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() -- 2.20.1