fix(application-form-fill): 清洗填表Word文件名

This commit is contained in:
2026-06-07 20:14:37 +08:00
parent ac5cf8bf7e
commit 13b543c99d
2 changed files with 31 additions and 1 deletions

View File

@@ -1,4 +1,5 @@
import zipfile
from pathlib import Path
import pytest
from docx import Document
@@ -119,3 +120,31 @@ def test_create_word_export_records_artifact_and_export(settings, tmp_path, djan
batch=batch,
artifact_type=ApplicationFormFillArtifact.ArtifactType.FILLED_TEMPLATE,
).exists()
def test_create_word_export_sanitizes_product_name_newlines(settings, tmp_path, django_user_model):
settings.MEDIA_ROOT = tmp_path
user = django_user_model.objects.create_user(username="owner", password="pass")
conversation = Conversation.objects.create(user=user, title="会话")
summary = FileSummaryBatch.objects.create(conversation=conversation, user=user, batch_no="FS-WORD-NL")
batch = ApplicationFormFillBatch.objects.create(
conversation=conversation,
user=user,
source_summary_batch=summary,
batch_no="AFF-WORD-NL",
product_name="原体核酸检测试剂盒(荧\n光PCR法",
work_dir=str(tmp_path / "aff" / "AFF-WORD-NL"),
)
template_path = tmp_path / "template.docx"
_template(template_path)
exported = create_word_export(
batch,
_spec(),
template_path,
{"product_name": MergedField("product_name", "产品名称", "原体核酸检测试剂盒", "说明书.txt", "证据", 0.8)},
)
assert "\n" not in exported.file_name
assert "\r" not in exported.file_name
assert Path(exported.storage_path).exists()