From 3abbbfb208ad9f00d660f9d051da9f0749a2e0a3 Mon Sep 17 00:00:00 2001 From: Esteban Galvis Date: Fri, 26 Jul 2024 10:37:27 -0500 Subject: [PATCH 1/2] fix: :bug: Fixed saving variables with \n --- menuflow/nodes/base.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/menuflow/nodes/base.py b/menuflow/nodes/base.py index f5e8dfa..8af5e70 100644 --- a/menuflow/nodes/base.py +++ b/menuflow/nodes/base.py @@ -145,7 +145,8 @@ def render_data(self, data: Dict | List | str) -> Dict | List | str: copy_variables = self.default_variables | self.room.all_variables try: - data = loads(data_template.render(**copy_variables)) + clear_variables = dumps(copy_variables).replace("\\n", " ") + data = loads(data_template.render(**loads(clear_variables))) data = convert_to_bool(data) return data except JSONDecodeError: From 2bf6b5ac7b9d60af8ea40ff27e9566dc3219623c Mon Sep 17 00:00:00 2001 From: Esteban Galvis Date: Fri, 26 Jul 2024 10:51:43 -0500 Subject: [PATCH 2/2] fix: :bug: Fixed saving variables with \n --- menuflow/nodes/base.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/menuflow/nodes/base.py b/menuflow/nodes/base.py index 8af5e70..61ea098 100644 --- a/menuflow/nodes/base.py +++ b/menuflow/nodes/base.py @@ -145,9 +145,12 @@ def render_data(self, data: Dict | List | str) -> Dict | List | str: copy_variables = self.default_variables | self.room.all_variables try: - clear_variables = dumps(copy_variables).replace("\\n", " ") - data = loads(data_template.render(**loads(clear_variables))) - data = convert_to_bool(data) + # if save variables have a string with \n, + # it will be replaced by ik-line-break to avoid errors when dict is dumped + # and before return, it will be replaced by \n again to keep the original string + clear_variables = dumps(copy_variables).replace("\\n", "ik-line-break") + data = data_template.render(**loads(clear_variables)) + data = convert_to_bool(loads(data.replace("ik-line-break", "\\n"))) return data except JSONDecodeError: data = data_template.render(**copy_variables)