On 11/9/03 10:51 am, Ilya Martynov <[EMAIL PROTECTED]> wrote:

> 
> Hi,
> 
> Is there built-in support in Net::LDAP for escaping parameters in
> search filters?  Something like DBI's placeholders or at least a
> method/subroutine in public API which can escape strings for me.
> 
> Example:
> 
>   my $result = $ldap->search(base   => $base,
>                              filter => "uid=$user");
> 
> I want to be able to ensure that string $user is properly escaped in
> search filter.
> 
> I've checked Net::LDAP docs but I haven't found anything. It seems
> there is some code for escaping and de-escaping strings (subs _escape
> and _unescape) for LDAP search queires in Net::LDAP::Filter but it
> doesn't seem to be a part of public API so I don't think it is wise to
> rely on them.

I think the easiest solution is to just construct the filter object "by
hand".

    filter => {
        'equalityMatch' => {
            'attributeDesc' => 'uid', 'assertionValue' => $user
        }
    },

To my mind this is more sensible than escaping the value into a string
representation, which then gets expanded out (and unescaped) into a HASH
ready for the encode!

It does however need some knowledge of the ASN.1. Or you could cheat and
create a Net::LDAP::Filter instance from a string, and then use the
debugger's 'x' command to display the filter HASH :-))

> BTW it seems there is a bug in Net::LDAP::Filter docs: it is
> documented to have method asn() but there is no such method in
> Net::LDAP::Filter.

You're right. Looking at LDAP.pm it would seem that it just passes the
Filter object as is to Convert::ASN1, so asn() is a no-op. I'll remove the
reference in the doc.

> P.S. Please Cc replies to me as I'm not subscribed to this mailing list.

Cheers,

Chris

Reply via email to