From 7de327fda0fabada21016d1d10c8edae272e62bb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=B4me=20Chilliet?= <come@opensides.be>
Date: Thu, 9 Nov 2017 14:48:26 +0100
Subject: [PATCH] :ambulance: fix(smarty): Use proper pattern matching instead
 of hack

The code was doing a search and replace for newlines as GOSA_LINE_BREAK
  to work no them as a single line.
This instead uses pattern options to make sure it works on multiline
 entry.

close #5704
---
 contrib/smarty/plugins/block.render.php | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/contrib/smarty/plugins/block.render.php b/contrib/smarty/plugins/block.render.php
index b8308571f..ba57fe4d0 100644
--- a/contrib/smarty/plugins/block.render.php
+++ b/contrib/smarty/plugins/block.render.php
@@ -42,8 +42,6 @@ function smarty_block_render($params, $text, &$smarty)
     return $text;
   }
 
-  $text = preg_replace ("/\n/", 'GOSA_LINE_BREAK', $text);
-
   /* Disable objects, but keep those active that have mode=read_active */
   if (!(isset($params['mode']) && ($params['mode'] == 'read_active') && preg_match('/(r|w)/', $acl))) {
     if (!preg_match('/ disabled(="disabled")?( |\/?>)/', $text)) {
@@ -53,11 +51,11 @@ function smarty_block_render($params, $text, &$smarty)
 
   /* Read only */
   if (preg_match('/r/i', $acl)) {
-    return preg_replace('/GOSA_LINE_BREAK/', "\n", $text);
+    return $text;
   }
 
   /* No acls */
-  if (preg_match('/type[\'"= ].*submit/', $text)) {
+  if (preg_match('/type[\'"= ].*submit/s', $text)) {
     $text = preg_replace('/submit/', 'button', $text);
   } else {
     $text = preg_replace('/value=[\'"][^"\']*[\'"]/', '', $text);
@@ -65,9 +63,9 @@ function smarty_block_render($params, $text, &$smarty)
 
   /* Remove select options */
   $from = array(
-    "#<option.*<\/option>#i",
-    "/(<textarea.*>).*(<\/textarea>)/i",
-    "/^(.*<input.*)checked(.*>.*)$/i"
+    "#<option.*<\/option>#is",
+    "/(<textarea.*>).*(<\/textarea>)/is",
+    "/^(.*<input.*)checked(.*>.*)$/isD"
   );
 
   $to = array(
@@ -77,7 +75,6 @@ function smarty_block_render($params, $text, &$smarty)
   );
 
   $text = preg_replace($from, $to, $text);
-  $text = preg_replace('/GOSA_LINE_BREAK/', "\n", $text);
 
   return $text;
 }
-- 
GitLab