From 6d1f9b0e0c7c6ac7f8688158e72bb0ae9ce8a396 Mon Sep 17 00:00:00 2001 From: Trenton H <797416+stumpylog@users.noreply.github.com> Date: Thu, 3 Oct 2024 10:08:40 -0700 Subject: [PATCH] Only santize custom field values which are underlying text --- src/documents/file_handling.py | 41 +++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/src/documents/file_handling.py b/src/documents/file_handling.py index d8884104a..eb1397f7d 100644 --- a/src/documents/file_handling.py +++ b/src/documents/file_handling.py @@ -241,24 +241,35 @@ def get_custom_fields_context( Given an Iterable of CustomFieldInstance, builds a dictionary mapping the field name to its type and value """ - return { - "custom_fields": { + field_data = {"custom_fields": {}} + for field_instance in custom_fields: + type_ = pathvalidate.sanitize_filename( + field_instance.field.data_type, + replacement_text="-", + ) + # String types need to be sanitized + if field_instance.field.data_type in { + CustomField.FieldDataType.DOCUMENTLINK, + CustomField.FieldDataType.MONETARY, + CustomField.FieldDataType.STRING, + CustomField.FieldDataType.URL, + }: + value = pathvalidate.sanitize_filename( + field_instance.value, + replacement_text="-", + ) + else: + value = field_instance.value + field_data["custom_fields"][ pathvalidate.sanitize_filename( field_instance.field.name, replacement_text="-", - ): { - "type": pathvalidate.sanitize_filename( - field_instance.field.data_type, - replacement_text="-", - ), - "value": pathvalidate.sanitize_filename( - str(field_instance.value), - replacement_text="-", - ), - } - for field_instance in custom_fields - }, - } + ) + ] = { + "type": type_, + "value": value, + } + return field_data def validate_template_and_render(