File tree Expand file tree Collapse file tree 1 file changed +3
-13
lines changed Expand file tree Collapse file tree 1 file changed +3
-13
lines changed Original file line number Diff line number Diff line change @@ -333,12 +333,7 @@ def format_ldap_query_string(query, **kwargs):
333
333
:param kwargs:
334
334
:return:
335
335
"""
336
- escape_chars = {
337
- six .text_type ('*' ): six .text_type ('\\ 2A' ),
338
- six .text_type ('(' ): six .text_type ('\\ 28' ),
339
- six .text_type (')' ): six .text_type ('\\ 29' ),
340
- six .text_type ('\\ ' ): six .text_type ('\\ 5C' ),
341
- }
336
+ escape_chars = six .text_type ('*()\\ &|<>~!:' )
342
337
escaped_args = {}
343
338
# kwargs is a dict that would normally be passed to string.format
344
339
for k , v in six .iteritems (kwargs ):
@@ -349,15 +344,10 @@ def format_ldap_query_string(query, **kwargs):
349
344
# with the escape chars if needed. since strings are immutable, we build a list of chars
350
345
# for the escaped string, and join it together after translating the string
351
346
escaped_list = []
352
- replace = six .text_type ('' )
353
347
for c in v :
354
- for s , r in six .iteritems (escape_chars ):
355
- if c == s :
356
- replace = r
357
- break
358
- if replace :
348
+ if c in escape_chars :
349
+ replace = six .text_type (hex (ord (c ))).replace ('0x' , '\\ ' )
359
350
escaped_list .append (replace )
360
- replace = six .text_type ('' )
361
351
else :
362
352
escaped_list .append (c )
363
353
escaped_args [k ] = six .text_type ('' ).join (escaped_list )
You can’t perform that action at this time.
0 commit comments