Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: double quotes will be trimmed from the search token #8035

Merged
merged 3 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions changelog/unreleased/fix-search-by-exact-mail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Bugfix: Fix search by exact email

Users can be searched by exact email by using double quotes on the search
parameter. Note that double quotes are required because the "@" char is
being interpreted by the parser.

https://github.com/owncloud/ocis/pull/8035
12 changes: 10 additions & 2 deletions services/graph/pkg/identity/odata.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package identity

import "github.com/CiscoM31/godata"
import (
"strings"

"github.com/CiscoM31/godata"
)

// GetExpandValues extracts the values of the $expand query parameter and
// returns them in a []string, rejects any $expand value that consists of more
Expand Down Expand Up @@ -37,5 +41,9 @@ func GetSearchValues(req *godata.GoDataQuery) (string, error) {
return "", godata.NotImplementedError("complex search queries are not supported")
}

return req.Search.Tree.Token.Value, nil
searchValue := req.Search.Tree.Token.Value
if strings.HasPrefix(searchValue, "\"") && strings.HasSuffix(searchValue, "\"") {
searchValue = strings.Trim(searchValue, "\"")
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: I guess in this case you can just call strings.Trim unconditionally. There is no need for the HasPrefix and HasSuffix calls. Or am I missing something?

The OData parser will already choke on strings that only contain a single double quote.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The OData parser will already choke on strings that only contain a single double quote.

I thought it was still possible. I'll remove the condition.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How are we dealing the same with single quotes?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think single quotes have a completely different meaning here and are handled by the OData parser. In this case, as far as I understand the odata specs, using single quotes here won't even work. (our parsers doesn't allow it here at least https://github.com/CiscoM31/godata)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does a user (the one who is on the keyboard...) know this difference...?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The user shouldn't need to worry about quoting at all.

The UI/client which is constructing the query should know the difference, yes.

return searchValue, nil
}