Commit 7de327fd authored by Côme Chilliet's avatar Côme Chilliet
Browse files

: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
Showing with 5 additions and 8 deletions
+5 -8
...@@ -42,8 +42,6 @@ function smarty_block_render($params, $text, &$smarty) ...@@ -42,8 +42,6 @@ function smarty_block_render($params, $text, &$smarty)
return $text; return $text;
} }
$text = preg_replace ("/\n/", 'GOSA_LINE_BREAK', $text);
/* Disable objects, but keep those active that have mode=read_active */ /* 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 (!(isset($params['mode']) && ($params['mode'] == 'read_active') && preg_match('/(r|w)/', $acl))) {
if (!preg_match('/ disabled(="disabled")?( |\/?>)/', $text)) { if (!preg_match('/ disabled(="disabled")?( |\/?>)/', $text)) {
...@@ -53,11 +51,11 @@ function smarty_block_render($params, $text, &$smarty) ...@@ -53,11 +51,11 @@ function smarty_block_render($params, $text, &$smarty)
/* Read only */ /* Read only */
if (preg_match('/r/i', $acl)) { if (preg_match('/r/i', $acl)) {
return preg_replace('/GOSA_LINE_BREAK/', "\n", $text); return $text;
} }
/* No acls */ /* No acls */
if (preg_match('/type[\'"= ].*submit/', $text)) { if (preg_match('/type[\'"= ].*submit/s', $text)) {
$text = preg_replace('/submit/', 'button', $text); $text = preg_replace('/submit/', 'button', $text);
} else { } else {
$text = preg_replace('/value=[\'"][^"\']*[\'"]/', '', $text); $text = preg_replace('/value=[\'"][^"\']*[\'"]/', '', $text);
...@@ -65,9 +63,9 @@ function smarty_block_render($params, $text, &$smarty) ...@@ -65,9 +63,9 @@ function smarty_block_render($params, $text, &$smarty)
/* Remove select options */ /* Remove select options */
$from = array( $from = array(
"#<option.*<\/option>#i", "#<option.*<\/option>#is",
"/(<textarea.*>).*(<\/textarea>)/i", "/(<textarea.*>).*(<\/textarea>)/is",
"/^(.*<input.*)checked(.*>.*)$/i" "/^(.*<input.*)checked(.*>.*)$/isD"
); );
$to = array( $to = array(
...@@ -77,7 +75,6 @@ function smarty_block_render($params, $text, &$smarty) ...@@ -77,7 +75,6 @@ function smarty_block_render($params, $text, &$smarty)
); );
$text = preg_replace($from, $to, $text); $text = preg_replace($from, $to, $text);
$text = preg_replace('/GOSA_LINE_BREAK/', "\n", $text);
return $text; return $text;
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment