Browse Source

Double-escape newlines in script string

Because they are stored twice: Once in the CFG of the script, and once in the CFG of the machine instance.

Fixes an issue reported here: https://github.com/Ultimaker/Cura/pull/3229
Ghostkeeper 6 years ago
parent
commit
3ae6b8c4c1
1 changed files with 2 additions and 2 deletions
  1. 2 2
      plugins/PostProcessingPlugin/PostProcessingPlugin.py

+ 2 - 2
plugins/PostProcessingPlugin/PostProcessingPlugin.py

@@ -208,7 +208,7 @@ class PostProcessingPlugin(QObject, Extension):
         for script_str in scripts_list_strs.split("\n"): #Encoded config files should never contain three newlines in a row. At most 2, just before section headers.
             if not script_str: #There were no scripts in this one (or a corrupt file caused more than 3 consecutive newlines here).
                 continue
-            script_str = script_str.replace("\\n", "\n").replace("\\\\", "\\") #Unescape escape sequences.
+            script_str = script_str.replace(r"\\\n", "\n").replace(r"\\\\", "\\\\") #Unescape escape sequences.
             script_parser = configparser.ConfigParser(interpolation = None)
             script_parser.optionxform = str #Don't transform the setting keys as they are case-sensitive.
             script_parser.read_string(script_str)
@@ -241,7 +241,7 @@ class PostProcessingPlugin(QObject, Extension):
             parser.write(serialized)
             serialized.seek(0)
             script_str = serialized.read()
-            script_str = script_str.replace("\\", "\\\\").replace("\n", "\\n") #Escape newlines because configparser sees those as section delimiters.
+            script_str = script_str.replace("\\\\", r"\\\\").replace("\n", r"\\\n") #Escape newlines because configparser sees those as section delimiters.
             script_list_strs.append(script_str)
 
         script_list_strs = "\n".join(script_list_strs) #ConfigParser should never output three newlines in a row when serialised, so it's a safe delimiter.