fix: _resolve_user_upload_path crashes on a non-dict resolve_upload result (#1715)

This commit is contained in:
Afonso Coutinho
2026-06-03 05:34:33 +01:00
committed by GitHub
parent 55c7a4a546
commit 29e19f326a
2 changed files with 24 additions and 1 deletions

View File

@@ -152,7 +152,7 @@ def _resolve_user_upload_path(
owner=owner, owner=owner,
auth_manager=auth_manager, auth_manager=auth_manager,
) )
if not resolved: if not isinstance(resolved, dict) or not resolved:
return None return None
path = resolved.get("path") path = resolved.get("path")
upload_dir = getattr(upload_handler, "upload_dir", None) upload_dir = getattr(upload_handler, "upload_dir", None)

View File

@@ -0,0 +1,23 @@
from routes.document_helpers import _resolve_user_upload_path
class _FakeHandler:
upload_dir = "/tmp/uploads"
def __init__(self, resolved):
self._resolved = resolved
def resolve_upload(self, upload_id, owner=None, auth_manager=None):
return self._resolved
def test_resolve_user_upload_path_handles_non_dict_resolution():
# resolve_upload normally returns a dict or None; a corrupt store could
# hand back a list/str, and the old resolved.get(...) then crashed.
assert _resolve_user_upload_path(_FakeHandler(["not", "a", "dict"]), "id1", None) is None
assert _resolve_user_upload_path(_FakeHandler("oops"), "id1", None) is None
def test_resolve_user_upload_path_tolerates_dict_without_path():
# a well-formed dict still flows through and returns None when no path
assert _resolve_user_upload_path(_FakeHandler({"other": 1}), "id1", None) is None