mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
fix: strip whitespace when parsing package keywords
Remove all extra whitespace when parsing Keywords to ensure we don't add empty keywords in the DB. Closes: #332 Signed-off-by: Leonidas Spyropoulos <artafinde@archlinux.org>
This commit is contained in:
parent
a509e40474
commit
1d6335363c
2 changed files with 31 additions and 1 deletions
|
@ -98,7 +98,7 @@ async def pkgbase_keywords(request: Request, name: str,
|
|||
|
||||
# Lowercase all keywords. Our database table is case insensitive,
|
||||
# and providing CI duplicates of keywords is erroneous.
|
||||
keywords = set(k.lower() for k in keywords.split(" "))
|
||||
keywords = set(k.lower() for k in keywords.split())
|
||||
|
||||
# Delete all keywords which are not supplied by the user.
|
||||
with db.begin():
|
||||
|
|
|
@ -1396,3 +1396,33 @@ def test_pkgbase_keywords(client: TestClient, user: User, package: Package):
|
|||
expected = ["abc", "test"]
|
||||
for i, keyword in enumerate(keywords):
|
||||
assert keyword.text.strip() == expected[i]
|
||||
|
||||
|
||||
def test_pkgbase_empty_keywords(client: TestClient, user: User, package: Package):
|
||||
endpoint = f"/pkgbase/{package.PackageBase.Name}"
|
||||
with client as request:
|
||||
resp = request.get(endpoint)
|
||||
assert resp.status_code == int(HTTPStatus.OK)
|
||||
|
||||
root = parse_root(resp.text)
|
||||
keywords = root.xpath('//a[@class="keyword"]')
|
||||
assert len(keywords) == 0
|
||||
|
||||
cookies = {"AURSID": user.login(Request(), "testPassword")}
|
||||
post_endpoint = f"{endpoint}/keywords"
|
||||
with client as request:
|
||||
resp = request.post(post_endpoint, data={
|
||||
"keywords": "abc test foo bar "
|
||||
}, cookies=cookies)
|
||||
assert resp.status_code == int(HTTPStatus.SEE_OTHER)
|
||||
|
||||
with client as request:
|
||||
resp = request.get(resp.headers.get("location"))
|
||||
assert resp.status_code == int(HTTPStatus.OK)
|
||||
|
||||
root = parse_root(resp.text)
|
||||
keywords = root.xpath('//a[@class="keyword"]')
|
||||
assert len(keywords) == 4
|
||||
expected = ["abc", "bar", "foo", "test"]
|
||||
for i, keyword in enumerate(keywords):
|
||||
assert keyword.text.strip() == expected[i]
|
||||
|
|
Loading…
Add table
Reference in a new issue