Skip to content

Commit c2c9a40

Browse files
fix: parsedn not handling attributes with equal char in value
This fixes an issue where attributes with equal chars in the value would not be correctly parsed. As we only set the AttributeTypeAndValue's Type field once and we reset it on the step to the next AttributeTypeAndValue we can assume if this field already has a value that it should not consider it the type/value separator. Fixes go-ldap#416
1 parent 6668c06 commit c2c9a40

File tree

4 files changed

+10
-2
lines changed

4 files changed

+10
-2
lines changed

dn.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ func ParseDN(str string) (*DN, error) {
156156
case char == '\\':
157157
unescapedTrailingSpaces = 0
158158
escaping = true
159-
case char == '=':
159+
case char == '=' && attribute.Type == "":
160160
attribute.Type = stringFromBuffer()
161161
// Special case: If the first character in the value is # the
162162
// following data is BER encoded so we can just fast forward

dn_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ func TestSuccessfulDNParsing(t *testing.T) {
5656
{[]*AttributeTypeAndValue{{"cn", "john.doe;weird name"}}},
5757
{[]*AttributeTypeAndValue{{"dc", "example"}}},
5858
{[]*AttributeTypeAndValue{{"dc", "net"}}}}},
59+
`cn=ZXhhbXBsZVRleHQ=,dc=dummy,dc=com`: {[]*RelativeDN{
60+
{[]*AttributeTypeAndValue{{"cn", "ZXhhbXBsZVRleHQ="}}},
61+
{[]*AttributeTypeAndValue{{"dc", "dummy"}}},
62+
{[]*AttributeTypeAndValue{{"dc", "com"}}}}},
5963
}
6064

6165
for test, answer := range testcases {

v3/dn.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ func ParseDN(str string) (*DN, error) {
156156
case char == '\\':
157157
unescapedTrailingSpaces = 0
158158
escaping = true
159-
case char == '=':
159+
case char == '=' && attribute.Type == "":
160160
attribute.Type = stringFromBuffer()
161161
// Special case: If the first character in the value is # the
162162
// following data is BER encoded so we can just fast forward

v3/dn_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ func TestSuccessfulDNParsing(t *testing.T) {
5656
{[]*AttributeTypeAndValue{{"cn", "john.doe;weird name"}}},
5757
{[]*AttributeTypeAndValue{{"dc", "example"}}},
5858
{[]*AttributeTypeAndValue{{"dc", "net"}}}}},
59+
`cn=ZXhhbXBsZVRleHQ=,dc=dummy,dc=com`: {[]*RelativeDN{
60+
{[]*AttributeTypeAndValue{{"cn", "ZXhhbXBsZVRleHQ="}}},
61+
{[]*AttributeTypeAndValue{{"dc", "dummy"}}},
62+
{[]*AttributeTypeAndValue{{"dc", "com"}}}}},
5963
}
6064

6165
for test, answer := range testcases {

0 commit comments

Comments
 (0)