Hi Peter,

On Friday, 18. August 2006 19:59, Peter Mogensen wrote:
> While programming a mod_perl2 application using Net::LDAP I observe that
>  all data comming from Net::LDAP have the internal Perl UTF8 flag
> cleared. (even if the attribute is a 1.3.6.1.4.1.1466.115.121.1.15,
> 'Directory String')
>
> I have data coming from a lot of sources and I would like to enforce the
> nice UTF-8 advice on this page:
> http://www.ahinea.com/en/tech/perl-unicode-struggle.html
>
> That is:
> "Always use UTF-8 to store and process your data.  Make sure perl knows
> you use it.  Make sure all your scalars, which contain Unicode, have the
> utf8 flag on.  Then you can safely concatenate strings.  Then you can
> use Unicode-related regular expressions, which gives you great powers
> for international text processing."
>
> ... which give me a problem with Net::LDAP, since the best place to make
> sure the UTF-8 flag is on on UTF-8 attributes would be in the library it
> self.
>
> Can I somehow tell Net::LDAP which attribute types are UTF-8 and make it
> set the flags internally?

Net::LDAP's version in CVS supports Perl's utf8 flag.
To stay compatible it normally behaves as the older versions of Net::LDAP.
But when giving the option raw followed by a regular expression to the 
constructor it treats all attributes not matching this regular expression as 
UTF-8 and converts them accordingly.
Since UTF8 = ASCII in the range 0 - 127 it does not hurt to not include
attributes with only numeric or ASCII values into the regex.
Here's an example:
        my $ldap = Net::LDAP->new('myhost.my..domain,
                                                raw => qr/;binary|jpegPhoto/io);
This would keep all attributes whose names contain ";binary" (e.g. 
certificates) and "jpegPhoto" as-is whie upgrading all other attributes'
values to UTF-8 perl strings.

The 'raw' option may be used with other methods and objects in perl-ldap too.
Have a look at the manual pages from the CCS version.

Please note: 
As part of the CVS this feature has not been havily tested,
although it worked for my purposes so far.
So, use at your own risk (as with all other software ;-)))

I'd be glad to get some feedback (success stories, error reports, 
patches, ...)

Regards
Peter

-- 
Peter Marschall
[EMAIL PROTECTED]

Reply via email to