Index: /CKEditor/tests/tt/4340/1.html
===================================================================
--- /CKEditor/tests/tt/4340/1.html	(revision 4421)
+++ /CKEditor/tests/tt/4340/1.html	(revision 4421)
@@ -0,0 +1,80 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
+	"http://www.w3.org/TR/html4/loose.dtd">
+<html>
+<head>
+	<title>Ticket: #4340 - Encoding Protection</title>
+	<meta name="tags" content="editor,unit,stable">
+	<script type="text/javascript" src="../../cktester/cell.js"></script>
+	<script>
+( function()
+{
+	var ts, tc, assert = CKEDITOR.test.assert;
+	function getFixedContent( id )
+	{
+		return CKEDITOR.test.fixHtml( CKEDITOR.document.getById( id ).getValue(), true, false )
+				.replace( /\s*cke_docType=".*?"/g, '' );
+	}
+
+	function getFixedValue( str )
+	{
+		return CKEDITOR.test.fixHtml( str, true, false )
+				.replace( /\s*cke_docType=".*?"/g, '' );
+	}
+
+	YAHOO.tool.TestRunner.add( ts = new CKEDITOR.test.suites.editorTestSuite(
+		{
+				editorName : 'test_editor_1',
+				name :document.title,
+				config :
+				{
+					forceSimpleAmpersand : true,
+					mailProtection : 'encode'
+				}
+		} ) );
+
+	ts.add( tc = new YAHOO.tool.TestCase(
+		{
+			/**
+			 * Test email href attribute are well protected into a function.
+			 */
+			test_htmldataprocessor_toDataFormat_protectEmail : function()
+			{
+				var editor = ts.editor,
+					dataprocessor = editor.dataProcessor,
+					input = '<a _cke_saved_href="mailto:tester@ckeditor.com?subject=subject&body=body">e-mail</a>',
+					output = '<a href=\"javascript:void(location.href=\'mailto:\'+String.fromCharCode(116,101,115,116,101,114,64,99,107,101,100,105,116,111,114,46,99,111,109)+\'?subject=subject&body=body\')\">e-mail</a>';
+
+				assert.areEqual( output, dataprocessor.toDataFormat( input, false )  );
+			},
+
+			/**
+			 * Test protected email function in href attribute are well restored.
+			 */
+			test_htmldataprocessor_toHtml_unProtectEmail : function()
+			{
+				var editor = ts.editor,
+					dataprocessor = editor.dataProcessor,
+					output = '<a href="mailto:tester@ckeditor.com?subject=subject&amp;body=body" _cke_saved_href="mailto:tester@ckeditor.com?subject=subject&amp;body=body">e-mail</a>',
+					input = '<a href=\"javascript:void(location.href=\'mailto:\'+String.fromCharCode(116,101,115,116,101,114,64,99,107,101,100,105,116,111,114,46,99,111,109)+\'?subject=subject&body=body\')\">e-mail</a>';
+
+				assert.areEqual( output, dataprocessor.toHtml( input, false )  );
+			},
+
+			/**
+			 * Test protected email function works as a whole.
+			 */
+			test_htmldataprocessor_toHtml_toDataFormat : function()
+			{
+				var editor = ts.editor,
+					dataprocessor = editor.dataProcessor,
+					input = '<a _cke_saved_href="mailto:tester@ckeditor.com?body=body&subject=subject">e-mail</a>',
+					result = '<a href="mailto:tester@ckeditor.com?body=body&amp;subject=subject" _cke_saved_href="mailto:tester@ckeditor.com?body=body&amp;subject=subject">e-mail</a>';
+				assert.areEqual( result, dataprocessor.toHtml( dataprocessor.toDataFormat( input, false ), false )  );
+			}
+		} ) );
+} )();
+	</script>
+</head>
+<body>
+</body>
+</html>
Index: /CKEditor/tests/tt/4340/2.html
===================================================================
--- /CKEditor/tests/tt/4340/2.html	(revision 4421)
+++ /CKEditor/tests/tt/4340/2.html	(revision 4421)
@@ -0,0 +1,80 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
+	"http://www.w3.org/TR/html4/loose.dtd">
+<html>
+<head>
+	<title>Ticket: #4340 - Function Protection </title>
+	<meta name="tags" content="editor,unit,stable">
+	<script type="text/javascript" src="../../cktester/cell.js"></script>
+	<script>
+( function()
+{
+	var ts, tc, assert = CKEDITOR.test.assert;
+	function getFixedContent( id )
+	{
+		return CKEDITOR.test.fixHtml( CKEDITOR.document.getById( id ).getValue(), true, false )
+				.replace( /\s*cke_docType=".*?"/g, '' );
+	}
+
+	function getFixedValue( str )
+	{
+		return CKEDITOR.test.fixHtml( str, true, false )
+				.replace( /\s*cke_docType=".*?"/g, '' );
+	}
+
+	YAHOO.tool.TestRunner.add( ts = new CKEDITOR.test.suites.editorTestSuite(
+		{
+				editorName : 'test_editor_1',
+				name :document.title,
+				config :
+				{
+					mailProtection : 'mt(BODY,SUBJECT,NAME,DOMAIN)'
+				}
+		} ) );
+
+	ts.add( tc = new YAHOO.tool.TestCase(
+		{
+			/**
+			 * Test email href attribute are well protected into a function.
+			 */
+			test_htmldataprocessor_toDataFormat_protectEmail : function()
+			{
+				var editor = ts.editor,
+					dataprocessor = editor.dataProcessor,
+					input = '<a _cke_saved_href="mailto:tester@ckeditor.com?subject=subject&body=body">e-mail</a>',
+					output = '<a href="javascript:mt(\'body\',\'subject\',\'tester\',\'ckeditor.com\')">e-mail</a>';
+
+				assert.areEqual( output, dataprocessor.toDataFormat( input, false )  );
+			},
+
+			/**
+			 * Test protected email function in href attribute are well restored.
+			 */
+			test_htmldataprocessor_toHtml_unProtectEmail : function()
+			{
+				var editor = ts.editor,
+					dataprocessor = editor.dataProcessor,
+					output = '<a href="mailto:tester@ckeditor.com?body=body\'text&subject=subject" _cke_saved_href="mailto:tester@ckeditor.com?body=body\'text&subject=subject">e-mail</a>',
+					input = '<a href="javascript:mt(\'body\\\'text\',\'subject\',\'tester\',\'ckeditor.com\')">e-mail</a>';
+
+				assert.areEqual( output, dataprocessor.toHtml( input, false )  );
+			},
+
+			/**
+			 * Test protected email function works as a whole.
+			 */
+			test_htmldataprocessor_toHtml_toDataFormat : function()
+			{
+				var editor = ts.editor,
+					dataprocessor = editor.dataProcessor,
+					input = '<a _cke_saved_href="mailto:tester@ckeditor.com?body=body&subject=subject">e-mail</a>',
+					result = '<a href="mailto:tester@ckeditor.com?body=body&subject=subject" _cke_saved_href="mailto:tester@ckeditor.com?body=body&subject=subject">e-mail</a>';
+				editor.config.mailProtection = 'mt(NAME,DOMAIN,BODY,SUBJECT)';
+				assert.areEqual( result, dataprocessor.toHtml( dataprocessor.toDataFormat( input, false ), false )  );
+			}
+		} ) );
+} )();
+	</script>
+</head>
+<body>
+</body>
+</html>
