Hi, On Monday 20 June 2005 19:51, Graham Barr wrote: > That was my guess, I just wanted confirmation. I guess LDIF.pm > needs to be rewritten without the use of paragraph mode.
The attached a patch should deal with the CR+LF vs. LF issues in LDIF.pm Please test and give me feedback. Peter -- Peter Marschall eMail: [EMAIL PROTECTED]
--- lib/Net/LDAP/LDIF.pm +++ lib/Net/LDAP/LDIF.pm 2005-06-27 13:25:45.000000000 +0200 @@ -79,35 +79,41 @@ sub _read_lines { my $self = shift; - my @ldif; - - { - local $/ = ""; # paragraph mode my $fh = $self->{'fh'}; + my @ldif = (); + my $entry = ''; + my $in_comment = 0; 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> || ''; - $self->eof(1) unless $ln; - $ln =~ s/\n //sg; - $ln =~ s/^#.*\n//mg; - chomp($ln); - $self->{_next_lines} = $ln; - } until ($self->{_next_lines} || $self->eof()); + + return @ldif if ($self->eof()); + + while (defined($ln = scalar <$fh>)) { + if ($ln =~ /^#/o) { # ignore 1st line of comments + $in_comment = 1; + } + else { + if ($ln =~ /^[ \t]/o) { # append wrapped line (if not in a comment) + $entry .= $ln if (!$in_comment); + } + else { + $in_comment = 0; + if ($ln =~ /^\r?\n$/o) { + # ignore empty line on start of entry + # empty line at non-empty entry indicate entry completion + last if (length($entry)); + } + else { + # append non-empty line + $entry .= $ln; + } + } + } } + $self->eof(1) if (!defined($ln)); + $entry =~ s/\r?\n //sgo; # un-wrap wrapped lines + $entry =~ s/\r?\n\t/ /sgo; # OpenLDAP extension !!! + @ldif = split(/^/, $entry); + map { s/\r?\n$//; } @ldif; @ldif; }