Closed
Description
Net::LDAP::DN.escape()
is meant to adhere to https://datatracker.ietf.org/doc/html/rfc2253#section-2.4, which defines the convention for escaping attribute values.
Here's the related code:
ruby-net-ldap/lib/net/ldap/dn.rb
Lines 192 to 216 in d6bb5c8
The code properly escapes the special characters included in the ESCAPES
hash, handling this case from the RFC:
o one of the characters ",", "+", """, "\", "<", ">" or ";"
But the problem occurs with the special cases involving '#' and space:
o a space or "#" character occurring at the beginning of the
string
o a space character occurring at the end of the string
Space and '#' aren't included in that hash, so if ESCAPE_RE
matches '^#', for instance, the lookup of ESCAPES['#']
returns nil, which causes "\\" + ESCAPES[char]
to throw a TypeError (no implicit conversion of nil into String)
.
A potential workaround:
def self.escape(string)
string.gsub(ESCAPE_RE) { |char| "\\" + (ESCAPES[char] || char) }
end