Hi Graham, hi Chris, hi list,
plaiying a bit with Net::LDAP::LDIF I found that Net::LDAP::LDIF
does not cope with LDIF files of the form
------------ >8 snip 8< ------------
# comment
#comment
dn: cn=x
....
------------ >8 snip 8< ------------
That is with LDIF files that have 2 or more comments separated by
blank lines.
The attached patch fixes this problem.
In addition to that it forbids empty entries when not at the nd of the file
and comments out a statement that ignores the first line of an entry if
the lines contains nothing but digits.
Maybe this statement is a remnant from pre LDIF v1 versions of
Net::LDAP::LDIF, but to me it seems strange to simply slurp away those lines
from each entry without telling the user that this may possibly be an error.
Peter
--
Peter Marschall
eMail: [EMAIL PROTECTED]
# patch to allow comments separated by blank lines in LDIF files
--- lib/Net/LDAP/LDIF.pm
+++ lib/Net/LDAP/LDIF.pm 2004-01-28 09:37:32.000000000 +0100
@@ -76,17 +76,20 @@
{
local $/ = "";
my $fh = $self->{'fh'};
- my $ln = $self->{_next_lines} || scalar <$fh>;
- unless ($ln) {
- $self->{_next_lines} = '';
- $self->{_current_lines} = '';
- $self->eof(1);
- return;
- }
- $ln =~ s/\n //sg;
- $ln =~ s/^#.*\n//mg;
- chomp($ln);
- $self->{_current_lines} = $ln;
+ my $ln;
+ do { # allow comments separated by blank lines
+ $ln = $self->{_next_lines} || scalar <$fh>;
+ unless ($ln) {
+ $self->{_next_lines} = '';
+ $self->{_current_lines} = '';
+ $self->eof(1);
+ return;
+ }
+ $ln =~ s/\n //sg;
+ $ln =~ s/^#.*\n//mg;
+ chomp($ln);
+ $self->{_current_lines} = $ln;
+ } until ($self->{_current_lines} || $self->eof());
chomp(@ldif = split(/^/, $ln));
do {
$ln = scalar <$fh> || '';
@@ -112,8 +115,13 @@
$self->_clear_error();
@ldif = $self->_read_lines;
- return unless @ldif;
- shift @ldif if @ldif && $ldif[0] !~ /\D/;
+
+ unless (@ldif) { # empty records are errors if not at eof
+ $self->_error("illegal empty LDIF entry") if (!$self->eof());
+ return;
+ }
+ # What does that mean ???
+ #shift @ldif if @ldif && $ldif[0] !~ /\D/;
if (@ldif and $ldif[0] =~ /^version:\s+(\d+)/) {
$self->{version} = $1;