Projet

Général

Profil

0004-ldap-encode-string-before-using-urlparse.quote-on-th.patch

Benjamin Dauvergne, 11 mars 2019 20:54

Télécharger (1,76 ko)

Voir les différences:

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(-)
src/authentic2/backends/ldap_backend.py
977 977
        '''Build the exernal id for the user, use attribute that eventually
978 978
           never change like GUID or UUID.
979 979
        '''
980
        l = []
980
        parts = []
981 981
        for attribute in external_id_tuple:
982 982
            quote = True
983 983
            if ':' in attribute:
984 984
                attribute, param = attribute.split(':')
985 985
                quote = 'noquote' not in param.split(',')
986
            v = attributes[attribute]
987
            if isinstance(v, list):
988
                v = v[0]
989
            v = force_text(v)
986
            part = attributes[attribute]
987
            if isinstance(part, list):
988
                part = part[0]
990 989
            if quote:
991
                v = urlparse.quote(v)
992
            l.append(v)
993
        return ' '.join(v for v in l)
990
                part = urlparse.quote(part.encode('utf-8'))
991
            parts.append(part)
992
        return ' '.join(part for part in parts)
994 993

  
995 994
    def lookup_by_username(self, username):
996 995
        User = get_user_model()
997
-