I have a piece of code where I build a search filter with some
variables, like this:
my $searchFilter =
"(&(objectClass=" . $portal->{ldapGroupObjectClass} . ")(|";
foreach ( split( $portal->{multiValuesSeparator}, $value ) ) {
$searchFilter .= "(" . $key . "=" . $_ . ")";
}
$searchFilter .= "))";
This works well, excepted when the value (in the key=value syntax)
contains a backslash ('\'). This is the case for example if the value
is a DN like this : cn=OUDOT\, Clement, ou=users, dc=example, dc=com
To make this works, I added this line :
$searchFilter =~ s/\\/\\\\/;
My question: is this a bug in my code, or can this be a Perl-LDAP bug?
I am using version 0.4001.
Thanks for your help,
Clément OUDOT
http://lemonldap-ng.org
Hi,
I will have a look to Net::LDAP::Filter, but I see in Net::LDAP that a
new Net::LDAP::Filter is created in the search subroutine when filter
is a string. Why do the Net::LDAP::Filter object do not escape the
special characters from the string? Am I misunderstanding the code?
Clément.
And what about doing this:
$filter = Net::LDAP::Filter::_escape( $filter );
Would this work?
Clément.
On Jul 20, 2011, at 8:26, Chris Ridd <chri...@mac.com> wrote:
>
>>
>>
>>
>
> Graham, should _escape be made public? It seems like it would be useful. Or is manipulating the data structure returned from new the better approach?
Perhaps a flag on the new call that indicates there are no escapes in the string so that the existing \, is not assumed to be a pre-existing escape and the \ gets escaped?
Frank
The solution seems ok to me. Should I open an issue on the CPAN tracker?
Clément.
On Wednesday, 20. July 2011, Graham Barr wrote:
> On Jul 20, 2011, at 07:32 , Francis Swasey wrote:
> > On Jul 20, 2011, at 8:26, Chris Ridd <chri...@mac.com> wrote:
> >> Graham, should _escape be made public? It seems like it would be useful.
> > Perhaps a flag on the new call that indicates there are no escapes in the
> > string so that the existing \, is not assumed to be a pre-existing
> > escape and the \ gets escaped?
>
> That would not work consistently. consider (attr=())
>
> Some guessing would have to go one to know that the first ) needs to be
> escaped
>
> I think exporting _escape as escape_ldap_filter is the best approach and
> users should use that as they build their filters
What about using the documented functions in Net::LDAP::Util ?
* escape_filter_value()
* unescape_filter_value()
And for DNs the equivalents
* escape_dn_value()
* unescape_dn_value()
Best regards
Peter
--
Peter Marschall
pe...@adpm.de
Indeed, that is exactly what I was looking for.
Thanks for the pointer.
Clément.