Skip to content

Commit

Permalink
Added safeNl2br() string helper, doesn't nl2br text inside <..>
Browse files Browse the repository at this point in the history
  • Loading branch information
cheesegrits committed Dec 20, 2016
1 parent 00f4b08 commit 179072d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
20 changes: 18 additions & 2 deletions components/com_fabrik/helpers/string.php
Original file line number Diff line number Diff line change
Expand Up @@ -1062,6 +1062,24 @@ public static function getRowClass($value, $prefix)
}


/**
* Apply nl2br only outside of chevroned tags, eq. not between <...>
*
* @param $string
*
* @return mixed
*/
public static function safeNl2br($string)
{
return preg_replace_callback(
'#(\r\n?|\n)(?![^<]*>|[^<>]*</)#s',
function ($matches) {
return nl2br($matches[0]);
},
$string
);
}

}

/**
Expand Down Expand Up @@ -1121,6 +1139,4 @@ public static function _($string, $jsSafe = false, $interpretBackSlashes = true,
// if we got this far, hand it to JText::_() as normal
return parent::_($string, $jsSafe, $interpretBackSlashes, $script);
}


}
6 changes: 3 additions & 3 deletions plugins/fabrik_element/textarea/textarea.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public function renderListData($data, stdClass &$thisRow, $opts = array())
{
for ($i = 0; $i < count($data); $i++)
{
$data[$i] = nl2br($data[$i]);
$data[$i] = FabrikString::safeNl2br($data[$i]);
}
}
else
Expand All @@ -138,7 +138,7 @@ public function renderListData($data, stdClass &$thisRow, $opts = array())
$this->convertDataToString($data);
}

$data = nl2br($data);
$data = FabrikString::safeNl2br($data);
}
}

Expand Down Expand Up @@ -281,7 +281,7 @@ public function render($data, $repeatCounter = 0)
{
if (!$this->useWysiwyg(false))
{
$value = nl2br($value);
$value = FabrikString::safeNl2br($value);
}

if ($value !== ''
Expand Down

0 comments on commit 179072d

Please sign in to comment.