Index: branches/2.8.x/CHANGELOG
===================================================================
--- branches/2.8.x/CHANGELOG	(revision 1655)
+++ branches/2.8.x/CHANGELOG	(revision 1656)
@@ -11,6 +11,8 @@
 ! = Update/Change
 ===============================================================================
 
+02 Apr-2012 Build 1656 Werner v.d.Decken(DarkViper)
+# fixed filter to serve malformed/nested HTML also.
 01 Apr-2012 Build 1655 Dietmar Woellbrink (Luisehahne)
 + add replyto to form module (see DEVINFOS)
 01 Apr-2012 Build 1654 Dietmar Woellbrink (Luisehahne)
Index: branches/2.8.x/wb/admin/interface/version.php
===================================================================
--- branches/2.8.x/wb/admin/interface/version.php	(revision 1655)
+++ branches/2.8.x/wb/admin/interface/version.php	(revision 1656)
@@ -51,5 +51,5 @@
 
 // check if defined to avoid errors during installation (redirect to admin panel fails if PHP error/warnings are enabled)
 if(!defined('VERSION')) define('VERSION', '2.8.3');
-if(!defined('REVISION')) define('REVISION', '1655');
+if(!defined('REVISION')) define('REVISION', '1656');
 if(!defined('SP')) define('SP', '');
Index: branches/2.8.x/wb/modules/output_filter/filters/filterCssToHead.php
===================================================================
--- branches/2.8.x/wb/modules/output_filter/filters/filterCssToHead.php	(revision 1655)
+++ branches/2.8.x/wb/modules/output_filter/filters/filterCssToHead.php	(revision 1656)
@@ -4,23 +4,24 @@
  * @param string $content
  * @return string
  */
-	function doFilterCssToHead($content) {
+	function doFilterCssToHead($sContent) {
 		// move css definitions into head section
-		$pattern1 = '/(?:<body.*?)(<link[^>]*?\"text\/css\".*?\/>)/si';
-		$pattern2 = '/(?:<body.*?)(<style[^>]*?\"text\/css\"[^>]*?>.*?<\/style>)/si';
-		while(preg_match($pattern1, $content, $matches)==1) {
-		// loop through all linked CSS
-			$insert = $matches[1];
-			$content = str_replace($insert, '', $content);
-			$insert = "\n".$insert."\n</head>\n<body";
-			$content = preg_replace('/<\/head>.*?<body/si', $insert, $content);
+
+		$sPattern1 = '/(?:<body.*?)(<link[^>]*?\"text\/css\".*?\/>)/si';
+		$sPattern2 = '/(?:<body.*?)(<style[^>]*?\"text\/css\"[^>]*?>.*?<\/style>)/si';
+		$aInsert = array();
+		while(preg_match($sPattern1, $sContent, $aMatches)) {
+			$aInsert[] = $aMatches[1];
+			$sContent = str_replace($aMatches[1], '', $sContent); 
 		}
-		while(preg_match($pattern2, $content, $matches)==1) {
-		// loop through all inline CSS
-			$insert = $matches[1];
-			$content = str_replace($insert, '', $content);
-			$insert = "\n".$insert."\n</head>\n<body";
-			$content = preg_replace('/<\/head>.*?<body/si', $insert, $content);
+		while(preg_match($sPattern2, $sContent, $aMatches)) {
+			$aInsert[] = $aMatches[1];
+			$sContent = str_replace($aMatches[1], '', $sContent);
 		}
-		return $content;
+		$aInsert = array_unique($aInsert);
+		if(sizeof($aInsert) > 0) {
+			$sInsert = "\n".implode("\n", $aInsert)."\n</head>\n<body";
+			$sContent = preg_replace('/<\/head>.*?<body/si', $sInsert, $sContent, 1);
+		}
+		return $sContent;
 	}
