From: Norbert K. <nor...@da...> - 2002-04-24 17:11:16
|
Hi Graham, I put the #xxxx issue in a separate mail. >> --- Util.pm-0.25_01 Tue Apr 23 20:35:04 2002 >> +++ Util.pm Tue Apr 23 21:16:17 2002 >> @@ -231,8 +231,8 @@ > >> sub canonical_dn($%) { >> - my $dn =3D shift or return ''; >> + my $dn =3D shift; >> + return $dn unless $dn; # empty DN or undef > > $dn =3D "0" ? This is another case to consider. > This should be return $dn unless $dn and length $dn; return $dn if $dn eq '' || !defined $dn ; # empty DN or undef This handles undef, '' and "0" (leads to an error later). >> my %opt =3D @_; >> >> # create array of hash representation >> my @rdns; >> if ( ref $dn eq 'ARRAY' ) { >> - @rdns =3D @{$dn}; >> + @rdns =3D $opt{reverse} ? reverse @{$dn} : @{$dn}; >> } else { >> - @rdns =3D ldap_explode_dn( $dn ) or return undef; #error condition >> + @rdns =3D ldap_explode_dn( $dn, reverse =3D> $opt{reverse} ); > > Does it really make sense for ldap_explode_dn todo the reverse ? I added a reverse option to ldap_explode_dn and though it would be a good=20 idea to use it from canonical_dn as well. Am I missing something? >> sub ldap_explode_dn($%) { >> - my $dn =3D shift or return; >> + my @emptydn =3D (); #empty DN array for scalar context >> + my $dn =3D shift; >> + return wantarray ? [] : \@emptydn if $dn eq ''; > > This does not make sense. You are returning a scalar ref > when wantarray is true. Did you mean > > return wantarray ? () : [] if $dn eq ''; I'm not that familar with these elements of Perl so it tell you what a I=20 actually had in mind: The return value of ldap_explode_dn should give the=20 user an indication, whether an invalid DN was passed in. The problem is now = that the (valid) empty DN '' explodes to an empty array. In the scalar=20 context one can return undef or a reference to an empty array but I don't=20 know to express this in list context. >> my %opt =3D @_; >> >> my (@dn, %rdn); >> + $dn =3D~ s/^<(.*)>$/$1/; #remove brackets > > why ? where is it defined that DNs have <> brackets ? There is a test case <UID=3Djsmith,O=3Dexample,C=3DUS> in the ldapbis = document. I=20 don't know where such could be defined. Kurt? --=20 Norbert Klasen, Dipl.-Inform. DAASI International GmbH phone: +49 7071 29 70336 Wilhelmstr. 106 fax: +49 7071 29 5114 72074 T=FCbingen email: nor...@da... Germany web: http://www.daasi.de |