Skip to content

Commit

Permalink
Merge pull request #412 from TomSellers/retain_spaces_in_RDN_values
Browse files Browse the repository at this point in the history
Net::LDAP::DN - Retain trailing spaces in RDN values in DNs
  • Loading branch information
HarlemSquirrel authored Apr 19, 2023
2 parents 7b3af68 + b53edf3 commit 3d03e60
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
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

0 comments on commit 3d03e60

Please sign in to comment.