Skip to content

Commit 233e925

Browse files
tschechnikerpre-commit-ci[bot]bigcat88
authored
Explicit set utf-8 headers for file operations (#157)
File operations need to have utf-8 headers otherwise special allowed characters will break the file action as they will encoded to ascii per default. If you have files with äöü etc. you will get an ascii encoding error cause of the reference in the Header. This fixes this issue Changes proposed in this pull request: * Set Headers to encode to UTF-8 on file operations --------- Signed-off-by: Tobias Tschech <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Alexander Piskun <[email protected]>
1 parent 0372e78 commit 233e925

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

nc_py_api/files/files.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from xml.etree import ElementTree
1212

1313
import xmltodict
14-
from httpx import Response
14+
from httpx import Headers, Response
1515

1616
from .._exceptions import NextcloudException, NextcloudExceptionNotFound, check_error
1717
from .._misc import clear_from_params_empty, random_string, require_capabilities
@@ -273,7 +273,7 @@ def move(self, path_src: Union[str, FsNode], path_dest: Union[str, FsNode], over
273273
self._session.user, path_dest.user_path if isinstance(path_dest, FsNode) else path_dest
274274
)
275275
dest = self._session.cfg.dav_endpoint + full_dest_path
276-
headers = {"Destination": dest, "Overwrite": "T" if overwrite else "F"}
276+
headers = Headers({"Destination": dest, "Overwrite": "T" if overwrite else "F"}, encoding="utf-8")
277277
response = self._session.dav(
278278
"MOVE",
279279
self._dav_get_obj_path(self._session.user, path_src),
@@ -295,7 +295,7 @@ def copy(self, path_src: Union[str, FsNode], path_dest: Union[str, FsNode], over
295295
self._session.user, path_dest.user_path if isinstance(path_dest, FsNode) else path_dest
296296
)
297297
dest = self._session.cfg.dav_endpoint + full_dest_path
298-
headers = {"Destination": dest, "Overwrite": "T" if overwrite else "F"}
298+
headers = Headers({"Destination": dest, "Overwrite": "T" if overwrite else "F"}, encoding="utf-8")
299299
response = self._session.dav(
300300
"COPY",
301301
self._dav_get_obj_path(self._session.user, path_src),
@@ -372,7 +372,7 @@ def trashbin_restore(self, path: Union[str, FsNode]) -> None:
372372
path = path.user_path if isinstance(path, FsNode) else path
373373

374374
dest = self._session.cfg.dav_endpoint + f"/trashbin/{self._session.user}/restore/{restore_name}"
375-
headers = {"Destination": dest}
375+
headers = Headers({"Destination": dest}, encoding="utf-8")
376376
response = self._session.dav(
377377
"MOVE",
378378
path=f"/trashbin/{self._session.user}/{path}",
@@ -416,7 +416,7 @@ def restore_version(self, file_object: FsNode) -> None:
416416
"""
417417
require_capabilities("files.versioning", self._session.capabilities)
418418
dest = self._session.cfg.dav_endpoint + f"/versions/{self._session.user}/restore/{file_object.name}"
419-
headers = {"Destination": dest}
419+
headers = Headers({"Destination": dest}, encoding="utf-8")
420420
response = self._session.dav(
421421
"MOVE",
422422
path=f"/versions/{self._session.user}/{file_object.user_path}",

0 commit comments

Comments
 (0)