dsbenghe / Novell.Directory.Ldap.NETStandard

.NET LDAP client library for .NET Standard >= 2.0, .NET Core >=1.0, NET5/NET6/NET7/NET8 - works with any LDAP protocol compatible directory server (including Microsoft Active Directory).
MIT License
558 stars 153 forks source link

Filter parsing throws on empty and/or #204

Closed jcracknell closed 6 months ago

jcracknell commented 2 years ago

Parsing (&) or (|) produces:

LdapLocalException: Expecting left parenthesis, found ")" (87) Filter Error
   at Novell.Directory.Ldap.Rfc2251.RfcFilter.FilterTokenizer.GetLeftParen()
   at Novell.Directory.Ldap.Rfc2251.RfcFilter.ParseFilter()

Strictly this appears to be forbidden by RFC2251, which states "at least one filter element MUST be present in an 'and' or 'or' choice^0", however it is probably worth a slight divergence as in practice I believe most implementations accept these as true and false filters respectively:

Note that it is possible to have an AND filter that does not encapsulate any components. This filter has a string representation of “(&)” and is called the LDAP “true” filter because it will match any entry.^1

This can likely be addressed with a one line change:

https://github.com/dsbenghe/Novell.Directory.Ldap.NETStandard/blob/3f13132ca0ccfac37b1fbfa45d320e537add1a07/src/Novell.Directory.Ldap.NETStandard/Rfc2251/RfcFilter.cs#L402-L415