mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-01-07 04:40:05 -06:00
7
changelog/unreleased/fix-int-queries.md
Normal file
7
changelog/unreleased/fix-int-queries.md
Normal file
@@ -0,0 +1,7 @@
|
||||
Bugfix: use NewNumericRangeInclusiveQuery for numeric literals
|
||||
|
||||
Some LDAP properties like `uidnumber` and `gidnumber` are numeric. When an OS tries to look up a user it will not only try to lookup the user by username, but also by the `uidnumber`: `(&(objectclass=posixAccount)(uidnumber=20000))`. The accounts backend for glauth was sending that as a string query `uid_number eq '20000'` and has been changed to send it as `uid_number eq 20000`. The removed quotes allow the parser in ocis-accounts to identify the numeric literal and use the NewNumericRangeInclusiveQuery instead of a TermQuery.
|
||||
|
||||
https://github.com/owncloud/ocis-glauth/issues/28
|
||||
https://github.com/owncloud/ocis-accounts/pull/68
|
||||
https://github.com/owncloud/ocis-glauth/pull/29
|
||||
@@ -2,6 +2,8 @@ package provider
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/CiscoM31/godata"
|
||||
"github.com/blevesearch/bleve"
|
||||
@@ -49,16 +51,25 @@ func recursiveBuildQuery(n *godata.ParseNode) (query.Query, error) {
|
||||
if n.Children[0].Token.Type != godata.FilterTokenLiteral {
|
||||
return nil, errors.New("equality expected a literal on the lhs")
|
||||
}
|
||||
if n.Children[1].Token.Type != godata.FilterTokenString {
|
||||
return nil, errors.New("equality expected a string on the rhs")
|
||||
if n.Children[1].Token.Type == godata.FilterTokenString {
|
||||
// string tokens are enclosed with 'some string'
|
||||
// ' is escaped as ''
|
||||
// TODO unescape '' as '
|
||||
// http://docs.oasis-open.org/odata/odata/v4.01/cs01/part2-url-conventions/odata-v4.01-cs01-part2-url-conventions.html#sec_URLComponents
|
||||
q := bleve.NewTermQuery(n.Children[1].Token.Value[1 : len(n.Children[1].Token.Value)-1])
|
||||
q.SetField(n.Children[0].Token.Value)
|
||||
return q, nil
|
||||
} else if n.Children[1].Token.Type == godata.FilterTokenInteger {
|
||||
v, err := strconv.ParseFloat(n.Children[1].Token.Value, 64)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
incl := true
|
||||
q := bleve.NewNumericRangeInclusiveQuery(&v, &v, &incl, &incl)
|
||||
q.SetField(n.Children[0].Token.Value)
|
||||
return q, nil
|
||||
}
|
||||
// string tokens are enclosed with 'some string'
|
||||
// ' is escaped as ''
|
||||
// TODO unescape '' as '
|
||||
// http://docs.oasis-open.org/odata/odata/v4.01/cs01/part2-url-conventions/odata-v4.01-cs01-part2-url-conventions.html#sec_URLComponents
|
||||
q := bleve.NewTermQuery(n.Children[1].Token.Value[1 : len(n.Children[1].Token.Value)-1])
|
||||
q.SetField(n.Children[0].Token.Value)
|
||||
return q, nil
|
||||
return nil, fmt.Errorf("equality expected a string or int on the rhs, got %d", n.Children[1].Token.Type)
|
||||
case "and":
|
||||
q := query.NewConjunctionQuery([]query.Query{})
|
||||
for _, child := range n.Children {
|
||||
|
||||
Reference in New Issue
Block a user