Skip to content

Commit 3d03e60

Browse files
Merge pull request #412 from TomSellers/retain_spaces_in_RDN_values
Net::LDAP::DN - Retain trailing spaces in RDN values in DNs
2 parents 7b3af68 + b53edf3 commit 3d03e60

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

lib/net/ldap/dn.rb

+5-5
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def each_pair
8181
value << char
8282
when ',' then
8383
state = :key
84-
yield key.string.strip, value.string.rstrip
84+
yield key.string.strip, value.string
8585
key = StringIO.new
8686
value = StringIO.new;
8787
else
@@ -93,7 +93,7 @@ def each_pair
9393
when '\\' then state = :value_normal_escape
9494
when ',' then
9595
state = :key
96-
yield key.string.strip, value.string.rstrip
96+
yield key.string.strip, value.string
9797
key = StringIO.new
9898
value = StringIO.new;
9999
else value << char
@@ -142,7 +142,7 @@ def each_pair
142142
when ' ' then state = :value_end
143143
when ',' then
144144
state = :key
145-
yield key.string.strip, value.string.rstrip
145+
yield key.string.strip, value.string
146146
key = StringIO.new
147147
value = StringIO.new;
148148
else raise Net::LDAP::InvalidDNError, "DN badly formed"
@@ -159,7 +159,7 @@ def each_pair
159159
when ' ' then state = :value_end
160160
when ',' then
161161
state = :key
162-
yield key.string.strip, value.string.rstrip
162+
yield key.string.strip, value.string
163163
key = StringIO.new
164164
value = StringIO.new;
165165
else raise Net::LDAP::InvalidDNError, "DN badly formed"
@@ -172,7 +172,7 @@ def each_pair
172172
raise Net::LDAP::InvalidDNError, "DN badly formed" unless
173173
[:value, :value_normal, :value_hexstring, :value_end].include? state
174174

175-
yield key.string.strip, value.string.rstrip
175+
yield key.string.strip, value.string
176176
end
177177

178178
##

test/test_dn.rb

+7-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ def test_escape_space
1414
assert_equal '\\ before_after\\ ', Net::LDAP::DN.escape(' before_after ')
1515
end
1616

17+
def test_retain_spaces
18+
dn = Net::LDAP::DN.new('CN=Foo.bar.baz, OU=Foo \ ,OU=\ Bar, O=Baz')
19+
assert_equal "CN=Foo.bar.baz, OU=Foo \\ ,OU=\\ Bar, O=Baz", dn.to_s
20+
assert_equal ["CN", "Foo.bar.baz", "OU", "Foo ", "OU", " Bar", "O", "Baz"], dn.to_a
21+
end
22+
1723
def test_escape_on_initialize
1824
dn = Net::LDAP::DN.new('cn', ',+"\\<>;', 'ou=company')
1925
assert_equal 'cn=\\,\\+\\"\\\\\\<\\>\\;,ou=company', dn.to_s
@@ -26,7 +32,7 @@ def test_to_a
2632

2733
def test_to_a_parenthesis
2834
dn = Net::LDAP::DN.new('cn = \ James , ou = "Comp\28ny" ')
29-
assert_equal ['cn', ' James', 'ou', 'Comp(ny'], dn.to_a
35+
assert_equal ['cn', ' James ', 'ou', 'Comp(ny'], dn.to_a
3036
end
3137

3238
def test_to_a_hash_symbol

0 commit comments

Comments
 (0)