diff --git a/src/arduino.cc/builder/prototypes_adder.go b/src/arduino.cc/builder/prototypes_adder.go
index ef2be7c2..fb1d392c 100644
--- a/src/arduino.cc/builder/prototypes_adder.go
+++ b/src/arduino.cc/builder/prototypes_adder.go
@@ -43,6 +43,10 @@ type PrototypesAdder struct{}
 func (s *PrototypesAdder) Run(context map[string]interface{}) error {
 	debugOutput := context[constants.CTX_DEBUG_PREPROCESSOR] != nil
 	source := context[constants.CTX_SOURCE].(string)
+
+	source = strings.Replace(source, "\r\n", "\n", -1)
+	source = strings.Replace(source, "\r", "\n", -1)
+
 	sourceRows := strings.Split(source, "\n")
 
 	if !utils.MapHas(context, constants.CTX_LINE_WHERE_TO_INSERT_PROTOTYPES) {
diff --git a/src/arduino.cc/builder/test/eol_processing/sketch.ino b/src/arduino.cc/builder/test/eol_processing/sketch.ino
new file mode 100644
index 00000000..9037a7fa
--- /dev/null
+++ b/src/arduino.cc/builder/test/eol_processing/sketch.ino
@@ -0,0 +1 @@
+int led = 7;

void setup() {
    
}

void loop() {
    
}
\ No newline at end of file
diff --git a/src/arduino.cc/builder/test/prototypes_adder_test.go b/src/arduino.cc/builder/test/prototypes_adder_test.go
index 0771ebaa..b3d95a9c 100644
--- a/src/arduino.cc/builder/test/prototypes_adder_test.go
+++ b/src/arduino.cc/builder/test/prototypes_adder_test.go
@@ -880,3 +880,44 @@ func TestPrototypesAdderSketchWithConst(t *testing.T) {
 	require.Equal(t, "#include <Arduino.h>\n#line 1\n", context[constants.CTX_INCLUDE_SECTION].(string))
 	require.Equal(t, "#line 1 \""+absoluteSketchLocation+"\"\nvoid setup();\n#line 2 \""+absoluteSketchLocation+"\"\nvoid loop();\n#line 4 \""+absoluteSketchLocation+"\"\nconst __FlashStringHelper* test();\n#line 6 \""+absoluteSketchLocation+"\"\nconst int test3();\n#line 8 \""+absoluteSketchLocation+"\"\nvolatile __FlashStringHelper* test2();\n#line 10 \""+absoluteSketchLocation+"\"\nvolatile int test4();\n#line 1\n", context[constants.CTX_PROTOTYPE_SECTION].(string))
 }
+
+func TestPrototypesAdderSketchWithDosEol(t *testing.T) {
+	DownloadCoresAndToolsAndLibraries(t)
+
+	context := make(map[string]interface{})
+
+	buildPath := SetupBuildPath(t, context)
+	defer os.RemoveAll(buildPath)
+
+	sketchLocation := filepath.Join("eol_processing", "sketch.ino")
+
+	context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"}
+	context[constants.CTX_TOOLS_FOLDERS] = []string{"downloaded_tools"}
+	context[constants.CTX_FQBN] = "arduino:avr:uno"
+	context[constants.CTX_SKETCH_LOCATION] = sketchLocation
+	context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = "10600"
+	context[constants.CTX_BUILT_IN_LIBRARIES_FOLDERS] = []string{"downloaded_libraries"}
+	context[constants.CTX_OTHER_LIBRARIES_FOLDERS] = []string{"libraries"}
+	context[constants.CTX_VERBOSE] = true
+
+	commands := []types.Command{
+		&builder.SetupHumanLoggerIfMissing{},
+
+		&builder.ContainerSetupHardwareToolsLibsSketchAndProps{},
+
+		&builder.ContainerMergeCopySketchFiles{},
+
+		&builder.ContainerFindIncludes{},
+
+		&builder.PrintUsedLibrariesIfVerbose{},
+		&builder.WarnAboutArchIncompatibleLibraries{},
+
+		&builder.ContainerAddPrototypes{},
+	}
+
+	for _, command := range commands {
+		err := command.Run(context)
+		NoError(t, err)
+	}
+	// only requires no error as result
+}