Skip to content

Commit c96cdd7

Browse files
committed
Save file line by line taking care of OS EOL
Should solve #6736
1 parent 20bfb17 commit c96cdd7

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,14 @@ static public String sanitizeName(String origName) {
940940
*/
941941
static public void saveFile(String str, File file) throws IOException {
942942
File temp = File.createTempFile(file.getName(), null, file.getParentFile());
943-
PApplet.saveStrings(temp, new String[] { str });
943+
// Split the file content using minimum common separator \n
944+
// then trim any other character (\r) so saveStrings can print it in the correct
945+
// format for every OS
946+
String strArray[] = str.split("\n");
947+
for (String item : strArray) {
948+
item.trim();
949+
}
950+
PApplet.saveStrings(temp, strArray);
944951

945952
try {
946953
file = file.getCanonicalFile();

0 commit comments

Comments
 (0)