From 41bee0a690a57b57624d80b550c6ecfac2169935 Mon Sep 17 00:00:00 2001 From: Martin Carpenter Date: Sat, 23 Jul 2011 03:31:42 +0200 Subject: [PATCH] Fix LDIF contination to single elided space RFC 2849 http://tools.ietf.org/html/rfc2849: SPACE = %x20 ; ASCII SP, space ... 2) Any non-empty line, including comment lines, in an LDIF file MAY be folded by inserting a line separator (SEP) and a SPACE. Folding MUST NOT occur before the first character of the line. In other words, folding a line into two lines, the first of which is empty, is not permitted. Any line that begins with a single space MUST be treated as a continuation of the previous (non-empty) line. When joining folded lines, exactly one space character at the beginning of each continued line must be discarded. Implementations SHOULD NOT fold lines in the middle of a multi-byte UTF-8 character. --- lib/net/ldap/dataset.rb | 4 ++-- test/test_ldif.rb | 11 +++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/net/ldap/dataset.rb b/lib/net/ldap/dataset.rb index 363d259..ffdee11 100644 --- a/lib/net/ldap/dataset.rb +++ b/lib/net/ldap/dataset.rb @@ -117,8 +117,8 @@ class Net::LDAP::Dataset < Hash while line new_line = io.gets - if new_line =~ /^[\s]+/ - line << " " << $' + if new_line =~ /^ / + line << $' else nextline = new_line diff --git a/test/test_ldif.rb b/test/test_ldif.rb index 77f8b86..275456a 100644 --- a/test/test_ldif.rb +++ b/test/test_ldif.rb @@ -31,8 +31,15 @@ class TestLdif < Test::Unit::TestCase end def test_ldif_with_continuation_lines - ds = Net::LDAP::Dataset::read_ldif(StringIO.new("dn: abcdefg\r\n hijklmn\r\n\r\n")) - assert_equal(true, ds.has_key?("abcdefg hijklmn")) + ds = Net::LDAP::Dataset::read_ldif(StringIO.new("dn: abcdefg\r\n hijklmn\r\n\r\n")) + assert_equal(true, ds.has_key?("abcdefghijklmn")) + end + + def test_ldif_with_continuation_lines_and_extra_whitespace + ds1 = Net::LDAP::Dataset::read_ldif(StringIO.new("dn: abcdefg\r\n hijklmn\r\n\r\n")) + assert_equal(true, ds1.has_key?("abcdefg hijklmn")) + ds2 = Net::LDAP::Dataset::read_ldif(StringIO.new("dn: abcdefg\r\n hij klmn\r\n\r\n")) + assert_equal(true, ds2.has_key?("abcdefghij klmn")) end # TODO, INADEQUATE. We need some more tests