fix(application-form-fill): 清洗填表Word文件名
This commit is contained in:
@@ -107,5 +107,6 @@ def _normalize_label(value: str) -> str:
|
|||||||
|
|
||||||
|
|
||||||
def _safe_filename(value: str) -> str:
|
def _safe_filename(value: str) -> str:
|
||||||
text = re.sub(r'[\\/:*?"<>|]+', "_", value or "")
|
text = re.sub(r"[\x00-\x1f\x7f]+", "", value or "")
|
||||||
|
text = re.sub(r'[\\/:*?"<>|]+', "_", text)
|
||||||
return text.strip()[:80] or "output"
|
return text.strip()[:80] or "output"
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import zipfile
|
import zipfile
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from docx import Document
|
from docx import Document
|
||||||
@@ -119,3 +120,31 @@ def test_create_word_export_records_artifact_and_export(settings, tmp_path, djan
|
|||||||
batch=batch,
|
batch=batch,
|
||||||
artifact_type=ApplicationFormFillArtifact.ArtifactType.FILLED_TEMPLATE,
|
artifact_type=ApplicationFormFillArtifact.ArtifactType.FILLED_TEMPLATE,
|
||||||
).exists()
|
).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()
|
||||||
|
|||||||
Reference in New Issue
Block a user