Skip to content

Commit 3e50aee

Browse files
committed
Save file line by line taking care of OS EOL
Fixes #6736
1 parent 31a26cb commit 3e50aee

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

arduino-core/src/processing/app/BaseNoGui.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -907,7 +907,14 @@ static public String sanitizeName(String origName) {
907907
*/
908908
static public void saveFile(String str, File file) throws IOException {
909909
File temp = File.createTempFile(file.getName(), null, file.getParentFile());
910-
PApplet.saveStrings(temp, new String[] { str });
910+
// Split the file content using minimum common separator \n
911+
// then trim any other character (\r) so saveStrings can print it in the correct
912+
// format for every OS
913+
String strArray[] = str.split("\n");
914+
for (String item : strArray) {
915+
item.trim();
916+
}
917+
PApplet.saveStrings(temp, strArray);
911918

912919
try {
913920
file = file.getCanonicalFile();

0 commit comments

Comments
 (0)