The function Net::LDAP::Filter::_escape($) does exactly what is needed here. It is not exported, not documented, and it seems to be a private function, but as Perl is not Java, you can use it. (But be aware that _escape() may disappear or change its behavior. In the worst case, copy that single-line function into your code.)

As a personal note: I think this function should be public and documented.

And a second note: I would prefer to have a placeholder mechanism like in DBI, so I don't have to care about escaping strings. Something like filter => ["(&(employeetype=?)(gender=?))",$type,$gender ]

Alexander

On 27.09.2006 19:37, Chris Ridd wrote:
On 27/9/06 5:21, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:

Hello all,

I am writing a simple search script using Net::LDAP.  The problem that I
am having is with the filter.

When I execute my script I get the following error message: "Bad filter at
line 15".

The attribute that I am use a part of the filter is "employeetype" and the
value is "consultant (pre-release)".  This is a legitimate value.

But it is not legitimate as-is in a search filter, because parentheses are
syntactically special in the string representations of these.

RFC 4515 says you need to replace ( in a filter value with \28 and ) with
\29. As you're writing a perl double-quoted string, you'll need to escape
those backslashes and thus you should end up writing:

    filter => "(employeetype=consultant \\28pre-release\\29)"

I think there's a note in the Net::LDAP::Filter docs about this escape
mechanism. If not, there should be.

Cheers,

Chris




--
Alexander Foken
mailto:[EMAIL PROTECTED]  http://www.foken.de/alexander/

Reply via email to