Index: /CKEditor/trunk/CHANGES.html
===================================================================
--- /CKEditor/trunk/CHANGES.html	(revision 3801)
+++ /CKEditor/trunk/CHANGES.html	(revision 3802)
@@ -92,4 +92,5 @@
 			source code.</li>
 		<li><a href="http://dev.fckeditor.net/ticket/3639">#3639</a> : Button size was inconsistent.</li>
+		<li><a href="http://dev.fckeditor.net/ticket/3874">#3874</a> : Paste as plain text in Safari loosing lines.</li>
 	</ul>
 	<h3>
Index: /CKEditor/trunk/_source/core/tools.js
===================================================================
--- /CKEditor/trunk/_source/core/tools.js	(revision 3801)
+++ /CKEditor/trunk/_source/core/tools.js	(revision 3802)
@@ -228,23 +228,30 @@
 			};
 
-			var fix1 = ( standard( '>' ) == '>' ) ?
+			var fix1 = ( standard( '\n' ).toLowerCase() == '<br>' ) ?
+				function( text )
+				{
+					// #3874 IE and Safari encode line-break into <br>
+					return standard( text ).replace( /<br>/gi, '\n' );
+				} :
+				standard;
+
+			var fix2 = ( standard( '>' ) == '>' ) ?
 				function( text )
 				{
 					// WebKit does't encode the ">" character, which makes sense, but
 					// it's different than other browsers.
-					return standard( text ).replace( />/g, '&gt;' );
-				} :
-				standard;
-
-			var fixNbsp = /&nbsp;/g;
-			var fix2 = ( standard( '  ' ) == '&nbsp; ' ) ?
-				function( text )
-				{
-					// #3785 IE8 changes spaces (>= 2) to &nbsp;
-					return fix1( text ).replace( fixNbsp, ' ' );
+					return fix1( text ).replace( />/g, '&gt;' );
 				} :
 				fix1;
 
-			this.htmlEncode = fix2;
+			var fix3 = ( standard( '  ' ) == '&nbsp; ' ) ?
+				function( text )
+				{
+					// #3785 IE8 changes spaces (>= 2) to &nbsp;
+					return fix2( text ).replace( /&nbsp;/g, ' ' );
+				} :
+				fix2;
+			
+			this.htmlEncode = fix3;
 
 			return this.htmlEncode( text );
Index: /CKEditor/trunk/_source/tests/core/tools.html
===================================================================
--- /CKEditor/trunk/_source/tests/core/tools.html	(revision 3801)
+++ /CKEditor/trunk/_source/tests/core/tools.html	(revision 3802)
@@ -10,6 +10,6 @@
 	<script type="text/javascript">
 	//<![CDATA[
-
-CKEDITOR.test.addTestCase( (function()
+var testcase;
+CKEDITOR.test.addTestCase( testcase = (function()
 {
 	// Local reference to the "assert" object.
@@ -76,4 +76,9 @@
 		{
 			assert.areSame( 'Test\'s &amp; "quote"', CKEDITOR.tools.htmlEncode( 'Test\'s & "quote"' ) );
+		},
+
+		test_htmlEncode_3874 : function()
+		{
+			assert.areSame( 'line1\nline2', CKEDITOR.tools.htmlEncode( 'line1\nline2' ) );
 		},
 
@@ -153,5 +158,5 @@
 	};
 })() );
-
+//window.onload = testcase.test_htmlEncode_3874;
 	//]]>
 	</script>
