Skip to content

Commit

Permalink
Fix escape_dn_chars
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian Best authored and Petr Viktorin committed May 24, 2019
1 parent 1d373da commit 44a593d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Lib/ldap/dn.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ def escape_dn_chars(s):
s = s.replace(';' ,'\\;')
s = s.replace('=' ,'\\=')
s = s.replace('\000' ,'\\\000')
if s[0]=='#' or s[0]==' ':
s = ''.join(('\\',s))
if s[-1]==' ':
s = ''.join((s[:-1],'\\ '))
if s[0]=='#' or s[0]==' ':
s = ''.join(('\\',s))
return s


Expand Down
5 changes: 5 additions & 0 deletions Tests/t_ldap_dn.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ def test_escape_dn_chars(self):
self.assertEqual(ldap.dn.escape_dn_chars('#foobar'), '\\#foobar')
self.assertEqual(ldap.dn.escape_dn_chars('foo bar'), 'foo bar')
self.assertEqual(ldap.dn.escape_dn_chars(' foobar'), '\\ foobar')
self.assertEqual(ldap.dn.escape_dn_chars(' '), '\\ ')
self.assertEqual(ldap.dn.escape_dn_chars(' '), '\\ \\ ')
self.assertEqual(ldap.dn.escape_dn_chars('foobar '), 'foobar\\ ')
self.assertEqual(ldap.dn.escape_dn_chars('f+o>o,b<a;r="\00"'), 'f\\+o\\>o\\,b\\<a\\;r\\=\\"\\\x00\\"')
self.assertEqual(ldap.dn.escape_dn_chars('foo\\,bar'), 'foo\\\\\\,bar')

def test_str2dn(self):
"""
Expand Down

0 comments on commit 44a593d

Please sign in to comment.