From 6ebc2104fcbfff2ae083098f7c2c08f7ae4f6679 Mon Sep 17 00:00:00 2001 From: Apehaenger Date: Tue, 20 Jul 2021 18:27:06 +0200 Subject: Fixed handling of UTF8 chars in filter value (#9) Thank you @Apehaenger --- filter.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'filter.go') diff --git a/filter.go b/filter.go index df3c86a..9f4c949 100644 --- a/filter.go +++ b/filter.go @@ -7,8 +7,10 @@ package ldap import ( "errors" "fmt" - "github.com/nmcclain/asn1-ber" "strings" + "unicode/utf8" + + ber "github.com/nmcclain/asn1-ber" ) const ( @@ -179,10 +181,13 @@ func compileFilter(filter string, pos int) (*ber.Packet, int, error) { default: attribute := "" condition := "" - for newPos < len(filter) && filter[newPos] != ')' { + + for w := 0; newPos < len(filter) && filter[newPos] != ')'; newPos += w { + rune, width := utf8.DecodeRuneInString(filter[newPos:]) + w = width switch { case packet != nil: - condition += fmt.Sprintf("%c", filter[newPos]) + condition += fmt.Sprintf("%c", rune) case filter[newPos] == '=': packet = ber.Encode(ber.ClassContext, ber.TypeConstructed, FilterEqualityMatch, nil, FilterMap[FilterEqualityMatch]) case filter[newPos] == '>' && filter[newPos+1] == '=': @@ -197,7 +202,6 @@ func compileFilter(filter string, pos int) (*ber.Packet, int, error) { case packet == nil: attribute += fmt.Sprintf("%c", filter[newPos]) } - newPos++ } if newPos == len(filter) { err = NewError(ErrorFilterCompile, errors.New("ldap: unexpected end of filter")) -- cgit v1.2.3