1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-13 18:24:57 +02:00

Fix issue processwire/processwire-issues#766 auto-remove UTF-8 value of &#8232 line-seperator entity in $sanitizer->text() function

This commit is contained in:
Ryan Cramer
2018-12-14 13:07:26 -05:00
parent e8d2eed1ba
commit b773c81ae9

View File

@@ -1022,7 +1022,8 @@ class Sanitizer extends Wire {
'truncateTail' => true, // if truncate necessary for maxLength, remove chars from tail? False to truncate from head.
'trim' => true, // trim whitespace from beginning/end, or specify character(s) to trim, or false to disable
);
static $alwaysReplace = null;
$truncated = false;
$options = array_merge($defaultOptions, $options);
if(isset($options['multiline'])) $options['multiLine'] = $options['multiline']; // common case error
@@ -1030,6 +1031,12 @@ class Sanitizer extends Wire {
if($options['maxLength'] < 0) $options['maxLength'] = 0;
if($options['maxBytes'] < 0) $options['maxBytes'] = 0;
if($alwaysReplace === null) {
$alwaysReplace = array(
mb_convert_encoding('&#8232;', 'UTF-8', 'HTML-ENTITIES') => '', // line-seperator that is sometimes copy/pasted
);
}
if($options['reduceSpace'] !== false && $options['stripSpace'] === false) {
// if reduceSpace option is used then provide necessary value for stripSpace option
$options['stripSpace'] = is_string($options['reduceSpace']) ? $options['reduceSpace'] : ' ';
@@ -1064,6 +1071,11 @@ class Sanitizer extends Wire {
if($options['convertEntities']) {
$value = $this->unentities($value, true, $options['outCharset']);
}
foreach($alwaysReplace as $find => $replace) {
if(strpos($value, $find) === false) continue;
$value = str_replace($find, $replace, $value);
}
if($options['stripSpace'] !== false) {
$c = is_string($options['stripSpace']) ? $options['stripSpace'] : '';
@@ -1968,7 +1980,6 @@ class Sanitizer extends Wire {
* @param string $str String to purify
* @param array $options See [config options](http://htmlpurifier.org/live/configdoc/plain.html).
* @return string Purified markup string.
* @throws WireException if given something other than a string
*
*/
public function purify($str, array $options = array()) {