Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Net::LDAP::DN - Retain trailing spaces in RDN values in DNs #412

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions lib/net/ldap/dn.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def each_pair
value << char
when ',' then
state = :key
yield key.string.strip, value.string.rstrip
yield key.string.strip, value.string
key = StringIO.new
value = StringIO.new;
else
Expand All @@ -93,7 +93,7 @@ def each_pair
when '\\' then state = :value_normal_escape
when ',' then
state = :key
yield key.string.strip, value.string.rstrip
yield key.string.strip, value.string
key = StringIO.new
value = StringIO.new;
else value << char
Expand Down Expand Up @@ -142,7 +142,7 @@ def each_pair
when ' ' then state = :value_end
when ',' then
state = :key
yield key.string.strip, value.string.rstrip
yield key.string.strip, value.string
key = StringIO.new
value = StringIO.new;
else raise Net::LDAP::InvalidDNError, "DN badly formed"
Expand All @@ -159,7 +159,7 @@ def each_pair
when ' ' then state = :value_end
when ',' then
state = :key
yield key.string.strip, value.string.rstrip
yield key.string.strip, value.string
key = StringIO.new
value = StringIO.new;
else raise Net::LDAP::InvalidDNError, "DN badly formed"
Expand All @@ -172,7 +172,7 @@ def each_pair
raise Net::LDAP::InvalidDNError, "DN badly formed" unless
[:value, :value_normal, :value_hexstring, :value_end].include? state

yield key.string.strip, value.string.rstrip
yield key.string.strip, value.string
end

##
Expand Down
8 changes: 7 additions & 1 deletion test/test_dn.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ def test_escape_space
assert_equal '\\ before_after\\ ', Net::LDAP::DN.escape(' before_after ')
end

def test_retain_spaces
dn = Net::LDAP::DN.new('CN=Foo.bar.baz, OU=Foo \ ,OU=\ Bar, O=Baz')
assert_equal "CN=Foo.bar.baz, OU=Foo \\ ,OU=\\ Bar, O=Baz", dn.to_s
assert_equal ["CN", "Foo.bar.baz", "OU", "Foo ", "OU", " Bar", "O", "Baz"], dn.to_a
end

def test_escape_on_initialize
dn = Net::LDAP::DN.new('cn', ',+"\\<>;', 'ou=company')
assert_equal 'cn=\\,\\+\\"\\\\\\<\\>\\;,ou=company', dn.to_s
Expand All @@ -26,7 +32,7 @@ def test_to_a

def test_to_a_parenthesis
dn = Net::LDAP::DN.new('cn = \ James , ou = "Comp\28ny" ')
assert_equal ['cn', ' James', 'ou', 'Comp(ny'], dn.to_a
assert_equal ['cn', ' James ', 'ou', 'Comp(ny'], dn.to_a
end

def test_to_a_hash_symbol
Expand Down