Skip to content

Commit d49ce32

Browse files
authored
Update v3 branch to sync with #111 (#268)
1 parent ec159f4 commit d49ce32

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

v3/search.go

+40
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,17 @@ func (e *Entry) GetAttributeValues(attribute string) []string {
7777
return []string{}
7878
}
7979

80+
// GetEqualFoldAttributeValues returns the values for the named attribute, or an
81+
// empty list. Attribute matching is done with strings.EqualFold.
82+
func (e *Entry) GetEqualFoldAttributeValues(attribute string) []string {
83+
for _, attr := range e.Attributes {
84+
if strings.EqualFold(attribute, attr.Name) {
85+
return attr.Values
86+
}
87+
}
88+
return []string{}
89+
}
90+
8091
// GetRawAttributeValues returns the byte values for the named attribute, or an empty list
8192
func (e *Entry) GetRawAttributeValues(attribute string) [][]byte {
8293
for _, attr := range e.Attributes {
@@ -87,6 +98,16 @@ func (e *Entry) GetRawAttributeValues(attribute string) [][]byte {
8798
return [][]byte{}
8899
}
89100

101+
// GetEqualFoldRawAttributeValues returns the byte values for the named attribute, or an empty list
102+
func (e *Entry) GetEqualFoldRawAttributeValues(attribute string) [][]byte {
103+
for _, attr := range e.Attributes {
104+
if strings.EqualFold(attr.Name, attribute) {
105+
return attr.ByteValues
106+
}
107+
}
108+
return [][]byte{}
109+
}
110+
90111
// GetAttributeValue returns the first value for the named attribute, or ""
91112
func (e *Entry) GetAttributeValue(attribute string) string {
92113
values := e.GetAttributeValues(attribute)
@@ -96,6 +117,16 @@ func (e *Entry) GetAttributeValue(attribute string) string {
96117
return values[0]
97118
}
98119

120+
// GetEqualFoldAttributeValue returns the first value for the named attribute, or "".
121+
// Attribute comparison is done with strings.EqualFold.
122+
func (e *Entry) GetEqualFoldAttributeValue(attribute string) string {
123+
values := e.GetEqualFoldAttributeValues(attribute)
124+
if len(values) == 0 {
125+
return ""
126+
}
127+
return values[0]
128+
}
129+
99130
// GetRawAttributeValue returns the first value for the named attribute, or an empty slice
100131
func (e *Entry) GetRawAttributeValue(attribute string) []byte {
101132
values := e.GetRawAttributeValues(attribute)
@@ -105,6 +136,15 @@ func (e *Entry) GetRawAttributeValue(attribute string) []byte {
105136
return values[0]
106137
}
107138

139+
// GetEqualFoldRawAttributeValue returns the first value for the named attribute, or an empty slice
140+
func (e *Entry) GetEqualFoldRawAttributeValue(attribute string) []byte {
141+
values := e.GetEqualFoldRawAttributeValues(attribute)
142+
if len(values) == 0 {
143+
return []byte{}
144+
}
145+
return values[0]
146+
}
147+
108148
// Print outputs a human-readable description
109149
func (e *Entry) Print() {
110150
fmt.Printf("DN: %s\n", e.DN)

v3/search_test.go

+19
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,22 @@ func TestNewEntry(t *testing.T) {
2929
iteration = iteration + 1
3030
}
3131
}
32+
33+
func TestGetAttributeValue(t *testing.T) {
34+
dn := "testDN"
35+
attributes := map[string][]string{
36+
"Alpha": {"value"},
37+
"bEta": {"value"},
38+
"gaMma": {"value"},
39+
"delTa": {"value"},
40+
"epsiLon": {"value"},
41+
}
42+
entry := NewEntry(dn, attributes)
43+
if entry.GetAttributeValue("Alpha") != "value" {
44+
t.Errorf("failed to get attribute in original case")
45+
}
46+
47+
if entry.GetEqualFoldAttributeValue("alpha") != "value" {
48+
t.Errorf("failed to get attribute in changed case")
49+
}
50+
}

0 commit comments

Comments
 (0)