mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-08 20:42:30 +08:00
Fix: Enforce 255-byte filename limit (#8290)
### What problem does this PR solve? - Add filename length validation (<=255 bytes) for document upload/rename in both HTTP and SDK APIs - Update error messages for consistency - Fix comparison operator in SDK from '>=' to '>' for filename length check ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue)
This commit is contained in:
@ -25,7 +25,7 @@ class TestDocumentsUpdated:
|
||||
"name, expected_message",
|
||||
[
|
||||
("new_name.txt", ""),
|
||||
(f"{'a' * (DOCUMENT_NAME_LIMIT - 3)}.txt", "The name should be less than 128 bytes"),
|
||||
(f"{'a' * (DOCUMENT_NAME_LIMIT - 4)}.txt", ""),
|
||||
(0, "AttributeError"),
|
||||
(None, "AttributeError"),
|
||||
("", "The extension of file can't be changed"),
|
||||
|
||||
@ -113,16 +113,17 @@ class TestDocumentsUpload:
|
||||
assert str(excinfo.value) == "No file selected!", str(excinfo.value)
|
||||
|
||||
@pytest.mark.p2
|
||||
def test_filename_exceeds_max_length(self, add_dataset_func, tmp_path):
|
||||
def test_filename_max_length(self, add_dataset_func, tmp_path):
|
||||
dataset = add_dataset_func
|
||||
fp = create_txt_file(tmp_path / f"{'a' * (DOCUMENT_NAME_LIMIT - 3)}.txt")
|
||||
fp = create_txt_file(tmp_path / f"{'a' * (DOCUMENT_NAME_LIMIT - 4)}.txt")
|
||||
|
||||
with fp.open("rb") as f:
|
||||
blob = f.read()
|
||||
|
||||
with pytest.raises(Exception) as excinfo:
|
||||
dataset.upload_documents([{"display_name": fp.name, "blob": blob}])
|
||||
assert str(excinfo.value) == "File name should be less than 128 bytes.", str(excinfo.value)
|
||||
documents = dataset.upload_documents([{"display_name": fp.name, "blob": blob}])
|
||||
for document in documents:
|
||||
assert document.dataset_id == dataset.id, str(document)
|
||||
assert document.name == fp.name, str(document)
|
||||
|
||||
@pytest.mark.p2
|
||||
def test_duplicate_files(self, add_dataset_func, tmp_path):
|
||||
|
||||
Reference in New Issue
Block a user