From 5e37e10267bb71984035fec1fc0c43b1c0f167f2 Mon Sep 17 00:00:00 2001
From: Stanislas Rolland <typo3@sjbr.ca>
Date: Fri, 2 Sep 2011 17:08:14 -0400
Subject: [PATCH] [BUGFIX] Leading and trailing blanks can't be edited by the
 RTE
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This patch will:
1. collapse repeating spaces into a single one;
2. replace leading and trailing spaces with non-breaking spaces;
3. replace any space following > and any space preceding < by a
   non-breaking space.

Change-Id: I06a8996f23e050e2e30cc2548c9c1bbafd5b41f0
Resolves: #16217
Releases: 4.5, 4.6
Reviewed-on: http://review.typo3.org/4758
Reviewed-by: Björn Pedersen
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
Reviewed-by: Stefan Neufeind
Reviewed-by: Xavier Perseguers
Tested-by: Xavier Perseguers
---
 typo3/sysext/rtehtmlarea/htmlarea/htmlarea.js | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/typo3/sysext/rtehtmlarea/htmlarea/htmlarea.js b/typo3/sysext/rtehtmlarea/htmlarea/htmlarea.js
index a43707a3c0db..91229f391824 100644
--- a/typo3/sysext/rtehtmlarea/htmlarea/htmlarea.js
+++ b/typo3/sysext/rtehtmlarea/htmlarea/htmlarea.js
@@ -2230,7 +2230,14 @@ HTMLArea.Editor = Ext.extend(Ext.util.Observable, {
 			case 'wysiwyg':
 				return this.iframe.getHTML();
 			case 'textmode':
-				return this.textArea.getValue();
+					// Collapse repeated spaces non-editable in wysiwyg
+					// Replace leading and trailing spaces non-editable in wysiwyg
+				return this.textArea.getValue().
+					replace(/[\x20]+/g, '\x20').
+					replace(/^\x20/g, '&nbsp;').
+					replace(/\x20$/g, '&nbsp;').
+					replace(/>\x20/g, '>&nbsp;').
+					replace(/\x20</g, '&nbsp;<');
 			default:
 				return '';
 		}
-- 
GitLab