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:
@ -47,9 +47,9 @@ class TestDocumentsUpdated:
|
||||
[
|
||||
("new_name.txt", 0, ""),
|
||||
(
|
||||
f"{'a' * (DOCUMENT_NAME_LIMIT - 3)}.txt",
|
||||
101,
|
||||
"The name should be less than 128 bytes.",
|
||||
f"{'a' * (DOCUMENT_NAME_LIMIT - 4)}.txt",
|
||||
0,
|
||||
"",
|
||||
),
|
||||
(
|
||||
0,
|
||||
|
||||
@ -13,7 +13,6 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
import string
|
||||
from concurrent.futures import ThreadPoolExecutor, as_completed
|
||||
|
||||
@ -128,13 +127,12 @@ class TestDocumentsUpload:
|
||||
assert res.json()["message"] == "No file selected!"
|
||||
|
||||
@pytest.mark.p2
|
||||
def test_filename_exceeds_max_length(self, HttpApiAuth, add_dataset_func, tmp_path):
|
||||
def test_filename_max_length(self, HttpApiAuth, add_dataset_func, tmp_path):
|
||||
dataset_id = add_dataset_func
|
||||
# filename_length = 129
|
||||
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")
|
||||
res = upload_documents(HttpApiAuth, dataset_id, [fp])
|
||||
assert res["code"] == 101
|
||||
assert res["message"] == "File name should be less than 128 bytes."
|
||||
assert res["code"] == 0
|
||||
assert res["data"][0]["name"] == fp.name
|
||||
|
||||
@pytest.mark.p2
|
||||
def test_invalid_dataset_id(self, HttpApiAuth, tmp_path):
|
||||
|
||||
Reference in New Issue
Block a user