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
This commit is contained in:
Ghostkeeper 2018-04-26 13:30:34 +02:00
parent d393316a27
commit 3ae6b8c4c1
No known key found for this signature in database
GPG Key ID: 5252B696FB5E7C7A

View File

@ -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.