Skip to content
Snippets Groups Projects
Unverified Commit cf1059d0 authored by reivilibre's avatar reivilibre Committed by GitHub
Browse files

Fix a long-standing bug where the user directory would return 1 more row than requested. (#14631)

parent 9e82caac
No related branches found
No related tags found
No related merge requests found
Fix a long-standing bug where the user directory would return 1 more row than requested.
\ No newline at end of file
...@@ -63,8 +63,8 @@ class UserDirectorySearchRestServlet(RestServlet): ...@@ -63,8 +63,8 @@ class UserDirectorySearchRestServlet(RestServlet):
body = parse_json_object_from_request(request) body = parse_json_object_from_request(request)
limit = body.get("limit", 10) limit = int(body.get("limit", 10))
limit = min(limit, 50) limit = max(min(limit, 50), 0)
try: try:
search_term = body["search_term"] search_term = body["search_term"]
......
...@@ -886,7 +886,7 @@ class UserDirectoryStore(UserDirectoryBackgroundUpdateStore): ...@@ -886,7 +886,7 @@ class UserDirectoryStore(UserDirectoryBackgroundUpdateStore):
limited = len(results) > limit limited = len(results) > limit
return {"limited": limited, "results": results} return {"limited": limited, "results": results[0:limit]}
def _parse_query_sqlite(search_term: str) -> str: def _parse_query_sqlite(search_term: str) -> str:
......
...@@ -448,6 +448,12 @@ class UserDirectoryStoreTestCase(HomeserverTestCase): ...@@ -448,6 +448,12 @@ class UserDirectoryStoreTestCase(HomeserverTestCase):
{"user_id": BOBBY, "display_name": "bobby", "avatar_url": None}, {"user_id": BOBBY, "display_name": "bobby", "avatar_url": None},
) )
@override_config({"user_directory": {"search_all_users": True}})
def test_search_user_limit_correct(self) -> None:
r = self.get_success(self.store.search_user_dir(ALICE, "bob", 1))
self.assertTrue(r["limited"])
self.assertEqual(1, len(r["results"]))
@override_config({"user_directory": {"search_all_users": True}}) @override_config({"user_directory": {"search_all_users": True}})
def test_search_user_dir_stop_words(self) -> None: def test_search_user_dir_stop_words(self) -> None:
"""Tests that a user can look up another user by searching for the start if its """Tests that a user can look up another user by searching for the start if its
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment