Skip to content

Commit 13008e4

Browse files
authored
allow using ; as RDN separator according to rfc2253 (#352)
1 parent f61ea45 commit 13008e4

File tree

4 files changed

+30
-4
lines changed

4 files changed

+30
-4
lines changed

dn.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,15 @@ func ParseDN(str string) (*DN, error) {
101101
buffer.WriteString(packet.Data.String())
102102
i += len(data) - 1
103103
}
104-
case char == ',' || char == '+':
104+
case char == ',' || char == '+' || char == ';':
105105
// We're done with this RDN or value, push it
106106
if len(attribute.Type) == 0 {
107107
return nil, errors.New("incomplete type, value pair")
108108
}
109109
attribute.Value = stringFromBuffer()
110110
rdn.Attributes = append(rdn.Attributes, attribute)
111111
attribute = new(AttributeTypeAndValue)
112-
if char == ',' {
112+
if char == ',' || char == ';' {
113113
dn.RDNs = append(dn.RDNs, rdn)
114114
rdn = new(RelativeDN)
115115
rdn.Attributes = make([]*AttributeTypeAndValue, 0)

dn_test.go

+13
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,17 @@ func TestSuccessfulDNParsing(t *testing.T) {
4545
{[]*AttributeTypeAndValue{
4646
{" A ", " 1 "},
4747
{" B ", " 2 "}}}}},
48+
49+
`cn=john.doe;dc=example,dc=net`: {[]*RelativeDN{
50+
{[]*AttributeTypeAndValue{{"cn", "john.doe"}}},
51+
{[]*AttributeTypeAndValue{{"dc", "example"}}},
52+
{[]*AttributeTypeAndValue{{"dc", "net"}}}}},
53+
54+
// Escaped `;` should not be treated as RDN
55+
`cn=john.doe\;weird name,dc=example,dc=net`: {[]*RelativeDN{
56+
{[]*AttributeTypeAndValue{{"cn", "john.doe;weird name"}}},
57+
{[]*AttributeTypeAndValue{{"dc", "example"}}},
58+
{[]*AttributeTypeAndValue{{"dc", "net"}}}}},
4859
}
4960

5061
for test, answer := range testcases {
@@ -147,6 +158,8 @@ func TestDNEqual(t *testing.T) {
147158
"cn=John Doe, ou=People, dc=sun.com",
148159
false,
149160
},
161+
// Test parsing of `;` for separating RDNs
162+
{"cn=john;dc=example,dc=com", "cn=john,dc=example,dc=com", true}, // missing values matter
150163
}
151164

152165
for i, tc := range testcases {

v3/dn.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,15 @@ func ParseDN(str string) (*DN, error) {
101101
buffer.WriteString(packet.Data.String())
102102
i += len(data) - 1
103103
}
104-
case char == ',' || char == '+':
104+
case char == ',' || char == '+' || char == ';':
105105
// We're done with this RDN or value, push it
106106
if len(attribute.Type) == 0 {
107107
return nil, errors.New("incomplete type, value pair")
108108
}
109109
attribute.Value = stringFromBuffer()
110110
rdn.Attributes = append(rdn.Attributes, attribute)
111111
attribute = new(AttributeTypeAndValue)
112-
if char == ',' {
112+
if char == ',' || char == ';' {
113113
dn.RDNs = append(dn.RDNs, rdn)
114114
rdn = new(RelativeDN)
115115
rdn.Attributes = make([]*AttributeTypeAndValue, 0)

v3/dn_test.go

+13
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,17 @@ func TestSuccessfulDNParsing(t *testing.T) {
4545
{[]*AttributeTypeAndValue{
4646
{" A ", " 1 "},
4747
{" B ", " 2 "}}}}},
48+
49+
`cn=john.doe;dc=example,dc=net`: {[]*RelativeDN{
50+
{[]*AttributeTypeAndValue{{"cn", "john.doe"}}},
51+
{[]*AttributeTypeAndValue{{"dc", "example"}}},
52+
{[]*AttributeTypeAndValue{{"dc", "net"}}}}},
53+
54+
// Escaped `;` should not be treated as RDN
55+
`cn=john.doe\;weird name,dc=example,dc=net`: {[]*RelativeDN{
56+
{[]*AttributeTypeAndValue{{"cn", "john.doe;weird name"}}},
57+
{[]*AttributeTypeAndValue{{"dc", "example"}}},
58+
{[]*AttributeTypeAndValue{{"dc", "net"}}}}},
4859
}
4960

5061
for test, answer := range testcases {
@@ -147,6 +158,8 @@ func TestDNEqual(t *testing.T) {
147158
"cn=John Doe, ou=People, dc=sun.com",
148159
false,
149160
},
161+
// Test parsing of `;` for separating RDNs
162+
{"cn=john;dc=example,dc=com", "cn=john,dc=example,dc=com", true}, // missing values matter
150163
}
151164

152165
for i, tc := range testcases {

0 commit comments

Comments
 (0)