Le 20 juillet 2011 13:13, Chris Ridd <chrisr...@mac.com> a écrit : > > On 20 Jul 2011, at 11:34, Clément OUDOT wrote: > >> 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? > > I think it is because the new() method sees the two characters "\," and > assumes you are escaping the comma. It is legal to escape an arbitrary > character like that, so your filter is valid but not what you want it to be. > > I'm not sure what the best way to use the Filter class really is, given that > it requires a validly escaped input string. I suppose you could call new() > with a string containing placeholders for each value, and then manipulate the > returned object to insert "proper" (and unescaped) values for each > placeholder. > > Something like this (typed in Mail): > > $filter = Net::LDAP::Filter->new("(&(objectClass=?)(|(foo=bar)))"); > $filter->{and}->[0]->{equalityMatch}->{assertionValue} = > $portal->{ldapGroupObjectClass}; > $filter->{and}->[1]->{or}->[0]->{equalityMatch}->{assertionValue} = "clement"; > $filter->{and}->[1]->{or}->[0]->{equalityMatch}->{assertionDesc} = "sn"; > > (etc) You'd need to loop adding new equalityMatch hashes to the 'or' array. > > Kind of ugly, but the alternative is for you to escape all your values before > building the string.
And what about doing this: $filter = Net::LDAP::Filter::_escape( $filter ); Would this work? Clément.