mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-07-15 06:55:48 +00:00
fix: process list patch values in http requests
This commit parses values from post request as well as always serializes values for the web interface
This commit is contained in:
@ -100,11 +100,11 @@ class PkgbuildPatch:
|
||||
return cls(**filter_json(dump, known_fields))
|
||||
|
||||
@classmethod
|
||||
def parse(cls, key: str | None, source: str) -> Self:
|
||||
def parse(cls, key: str | None, source: str | list[str]) -> Self:
|
||||
"""
|
||||
parse string value to the PKGBUILD patch value. This method simply takes string, tries to identify it as array
|
||||
or just string and return the respective value. Functions are returned as is. Shell arrays and single values
|
||||
are returned without quotes
|
||||
are returned without quotes. If source is ``list``, then value is returned as is
|
||||
|
||||
Args:
|
||||
key(str | None): variable key
|
||||
@ -118,6 +118,9 @@ class PkgbuildPatch:
|
||||
case function if key is not None and key.endswith("()"):
|
||||
# the key looks like a function, no further processing should be applied here
|
||||
return function
|
||||
case list():
|
||||
# do not try to perform operations on the list, just return as is
|
||||
return source
|
||||
case shell_array if shell_array.startswith("(") and shell_array.endswith(")"):
|
||||
# the source value looks like shell array, remove brackets and parse with shlex
|
||||
return shlex.split(shell_array[1:-1])
|
||||
|
@ -101,6 +101,6 @@ class PatchesView(StatusViewGuard, BaseView):
|
||||
except Exception as ex:
|
||||
raise HTTPBadRequest(reason=str(ex))
|
||||
|
||||
self.service().package_patches_update(package_base, PkgbuildPatch(key, value))
|
||||
self.service().package_patches_update(package_base, PkgbuildPatch.parse(key, value))
|
||||
|
||||
raise HTTPNoContent
|
||||
|
@ -68,7 +68,7 @@ class AddView(BaseView):
|
||||
try:
|
||||
data = await self.request.json()
|
||||
packages = self.get_non_empty(lambda key: [package for package in data[key] if package], "packages")
|
||||
patches = [PkgbuildPatch(patch["key"], patch.get("value", "")) for patch in data.get("patches", [])]
|
||||
patches = [PkgbuildPatch.parse(patch["key"], patch.get("value", "")) for patch in data.get("patches", [])]
|
||||
except Exception as ex:
|
||||
raise HTTPBadRequest(reason=str(ex))
|
||||
|
||||
|
@ -68,7 +68,7 @@ class RequestView(BaseView):
|
||||
try:
|
||||
data = await self.request.json()
|
||||
packages = self.get_non_empty(lambda key: [package for package in data[key] if package], "packages")
|
||||
patches = [PkgbuildPatch(patch["key"], patch.get("value", "")) for patch in data.get("patches", [])]
|
||||
patches = [PkgbuildPatch.parse(patch["key"], patch.get("value", "")) for patch in data.get("patches", [])]
|
||||
except Exception as ex:
|
||||
raise HTTPBadRequest(reason=str(ex))
|
||||
|
||||
|
Reference in New Issue
Block a user