mirror of
https://git.mirrors.martin98.com/https://github.com/infiniflow/ragflow.git
synced 2025-08-13 02:00:18 +08:00
Fix: check the file name length. (#6083)
### What problem does this PR solve? #6060 ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue)
This commit is contained in:
parent
f0601afa75
commit
5c8ad6702a
@ -136,6 +136,10 @@ def upload(dataset_id, tenant_id):
|
||||
return get_result(
|
||||
message="No file selected!", code=settings.RetCode.ARGUMENT_ERROR
|
||||
)
|
||||
if len(file_obj.filename.encode("utf-8")) >= 128:
|
||||
return get_result(
|
||||
message="File name should be less than 128 bytes.", code=settings.RetCode.ARGUMENT_ERROR
|
||||
)
|
||||
'''
|
||||
# total size
|
||||
total_size = 0
|
||||
@ -246,6 +250,11 @@ def update_doc(tenant_id, dataset_id, document_id):
|
||||
DocumentService.update_meta_fields(document_id, req["meta_fields"])
|
||||
|
||||
if "name" in req and req["name"] != doc.name:
|
||||
if len(req["name"].encode("utf-8")) >= 128:
|
||||
return get_result(
|
||||
message="The name should be less than 128 bytes.",
|
||||
code=settings.RetCode.ARGUMENT_ERROR,
|
||||
)
|
||||
if (
|
||||
pathlib.Path(req["name"].lower()).suffix
|
||||
!= pathlib.Path(doc.name.lower()).suffix
|
||||
|
@ -139,10 +139,9 @@ class TestUploadDocuments:
|
||||
# filename_length = 129
|
||||
fp = create_txt_file(tmp_path / f"{'a' * (DOCUMENT_NAME_LIMIT - 3)}.txt")
|
||||
res = upload_documnets(get_http_api_auth, ids[0], [fp])
|
||||
assert res["code"] == 500
|
||||
assert res["code"] == 101
|
||||
assert (
|
||||
res["message"]
|
||||
== f"{'a' * (DOCUMENT_NAME_LIMIT - 3)}.txt: Exceed the maximum length of file name!"
|
||||
res["message"].find("128") >= 0
|
||||
)
|
||||
|
||||
def test_invalid_dataset_id(self, get_http_api_auth, tmp_path):
|
||||
|
Loading…
x
Reference in New Issue
Block a user