mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
fix(rpc): suggestions should only suggest based on <keyword>%
Previously, Python code was looking for suggestions based on `%<keyword>%`. This was inconsistent with PHP's suggestion implementation and cause more records to be bundled with a suggestion, along with supplying misleading suggestions. Closes #343 Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
parent
9791704632
commit
a1a88ea872
2 changed files with 19 additions and 2 deletions
|
@ -332,7 +332,7 @@ class RPC:
|
|||
models.PackageBase
|
||||
).filter(
|
||||
and_(models.PackageBase.PackagerUID.isnot(None),
|
||||
models.Package.Name.like(f"%{arg}%"))
|
||||
models.Package.Name.like(f"{arg}%"))
|
||||
).order_by(models.Package.Name.asc()).limit(20)
|
||||
return [pkg.Name for pkg in packages]
|
||||
|
||||
|
@ -341,9 +341,10 @@ class RPC:
|
|||
if not args:
|
||||
return []
|
||||
|
||||
arg = args[0]
|
||||
packages = db.query(models.PackageBase.Name).filter(
|
||||
and_(models.PackageBase.PackagerUID.isnot(None),
|
||||
models.PackageBase.Name.like(f"%{args[0]}%"))
|
||||
models.PackageBase.Name.like(f"{arg}%"))
|
||||
).order_by(models.PackageBase.Name.asc()).limit(20)
|
||||
return [pkg.Name for pkg in packages]
|
||||
|
||||
|
|
|
@ -551,6 +551,14 @@ def test_rpc_suggest_pkgbase(client: TestClient, packages: List[Package]):
|
|||
data = response.json()
|
||||
assert data == []
|
||||
|
||||
# Test that suggestions are only given based on the beginning
|
||||
# of the keyword string.
|
||||
params["arg"] = "ther-pkg"
|
||||
with client as request:
|
||||
response = request.get("/rpc", params=params)
|
||||
data = response.json()
|
||||
assert data == []
|
||||
|
||||
|
||||
def test_rpc_suggest(client: TestClient, packages: List[Package]):
|
||||
params = {"v": 5, "type": "suggest", "arg": "other"}
|
||||
|
@ -573,6 +581,14 @@ def test_rpc_suggest(client: TestClient, packages: List[Package]):
|
|||
data = response.json()
|
||||
assert data == []
|
||||
|
||||
# Test that suggestions are only given based on the beginning
|
||||
# of the keyword string.
|
||||
params["arg"] = "ther-pkg"
|
||||
with client as request:
|
||||
response = request.get("/rpc", params=params)
|
||||
data = response.json()
|
||||
assert data == []
|
||||
|
||||
|
||||
def mock_config_getint(section: str, key: str):
|
||||
if key == "request_limit":
|
||||
|
|
Loading…
Add table
Reference in a new issue