mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
fix: encode package name in URL for source files
Package(Base) names might include characters that require url-encoding Signed-off-by: moson-mo <mo-son@mailbox.org>
This commit is contained in:
parent
8aac842307
commit
7d06c9ab97
2 changed files with 8 additions and 1 deletions
|
@ -1,6 +1,7 @@
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from http import HTTPStatus
|
from http import HTTPStatus
|
||||||
from typing import Tuple, Union
|
from typing import Tuple, Union
|
||||||
|
from urllib.parse import quote_plus
|
||||||
|
|
||||||
import orjson
|
import orjson
|
||||||
from fastapi import HTTPException
|
from fastapi import HTTPException
|
||||||
|
@ -246,5 +247,5 @@ def source_uri(pkgsrc: models.PackageSource) -> Tuple[str, str]:
|
||||||
elif "://" in pkgsrc.Source:
|
elif "://" in pkgsrc.Source:
|
||||||
return pkgsrc.Source, pkgsrc.Source
|
return pkgsrc.Source, pkgsrc.Source
|
||||||
path = config.get("options", "source_file_uri")
|
path = config.get("options", "source_file_uri")
|
||||||
pkgbasename = pkgsrc.Package.PackageBase.Name
|
pkgbasename = quote_plus(pkgsrc.Package.PackageBase.Name)
|
||||||
return pkgsrc.Source, path % (pkgsrc.Source, pkgbasename)
|
return pkgsrc.Source, path % (pkgsrc.Source, pkgbasename)
|
||||||
|
|
|
@ -109,6 +109,12 @@ def test_source_uri_file(package: Package):
|
||||||
expected = source_file_uri % (pkgsrc.Source, package.PackageBase.Name)
|
expected = source_file_uri % (pkgsrc.Source, package.PackageBase.Name)
|
||||||
assert (file, uri) == (FILE, expected)
|
assert (file, uri) == (FILE, expected)
|
||||||
|
|
||||||
|
# test URL encoding
|
||||||
|
pkgsrc.Package.PackageBase.Name = "test++"
|
||||||
|
file, uri = util.source_uri(pkgsrc)
|
||||||
|
expected = source_file_uri % (pkgsrc.Source, "test%2B%2B")
|
||||||
|
assert uri == expected
|
||||||
|
|
||||||
|
|
||||||
def test_source_uri_named_uri(package: Package):
|
def test_source_uri_named_uri(package: Package):
|
||||||
FILE = "test"
|
FILE = "test"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue