From b18c5df888effa9caa02f95a1953a4063d7f662b Mon Sep 17 00:00:00 2001
From: Daniel Hornung <d.hornung@indiscale.com>
Date: Thu, 21 Mar 2024 12:05:40 +0100
Subject: [PATCH] FIX: Regression from handling of illegal characters.

---
 .gitignore                                        |  1 +
 .../table_json_conversion/fill_xlsx.py            | 15 +++++++++------
 2 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/.gitignore b/.gitignore
index 4c175607..2b50c0fc 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,6 +3,7 @@
 src/caosadvancedtools/version.py
 
 # compiled python and dist stuff
+.venv
 *.egg
 .eggs
 *.egg-info/
diff --git a/src/caosadvancedtools/table_json_conversion/fill_xlsx.py b/src/caosadvancedtools/table_json_conversion/fill_xlsx.py
index 88356ccc..8e93767e 100644
--- a/src/caosadvancedtools/table_json_conversion/fill_xlsx.py
+++ b/src/caosadvancedtools/table_json_conversion/fill_xlsx.py
@@ -308,8 +308,13 @@ out: union[dict, None]
 
             # collecting the data
             assert isinstance(content, list)
-            content = [str(x) for x in content]
-            value = ";".join(content)  # TODO we need escaping of values
+            if len(content) > 1:
+                content = [ILLEGAL_CHARACTERS_RE.sub("", str(x)) for x in content]
+                value = ";".join(content)  # TODO we need escaping of values
+            else:
+                value = content[0]
+                if isinstance(value, str):
+                    value =  ILLEGAL_CHARACTERS_RE.sub("", value)
             path_str = p2s(path)
             assert path_str not in insertables
             insertables[path_str] = value
@@ -333,8 +338,7 @@ out: union[dict, None]
             if insert_row is None:
                 insert_row = _next_row_index(sheet)
 
-            sheet.cell(row=insert_row+1, column=col_index+1,
-                       value=ILLEGAL_CHARACTERS_RE.sub("", value))
+            sheet.cell(row=insert_row+1, column=col_index+1, value=value)
 
         # Insert foreign keys
         if insert_row is not None and sheet is not None and _is_exploded_sheet(sheet):
@@ -345,8 +349,7 @@ out: union[dict, None]
                 raise
             for index, path in ((f.index, f.path) for f in foreigns.values()):
                 value = context[path]
-                sheet.cell(row=insert_row+1, column=index+1,
-                           value=ILLEGAL_CHARACTERS_RE.sub("", value))
+                sheet.cell(row=insert_row+1, column=index+1, value=value)
 
         return None
 
-- 
GitLab