1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-15 11:14:12 +02:00

Fix issue with $sanitizer->truncate() method truncating more than it should sometimes due to entity encoding of punctuation

This commit is contained in:
Ryan Cramer
2020-09-10 09:23:07 -04:00
parent 5fce455fbd
commit 90ac2c90e9

View File

@@ -464,6 +464,8 @@ class WireTextTools extends Wire {
*/ */
function truncate($str, $maxLength, $options = array()) { function truncate($str, $maxLength, $options = array()) {
$ent = __(true, 'entityEncode', false);
$defaults = array( $defaults = array(
'type' => 'word', // word, punctuation, sentence, or block 'type' => 'word', // word, punctuation, sentence, or block
'maximize' => true, // include as much as possible within the type and maxLength (false=include as little as possible) 'maximize' => true, // include as much as possible within the type and maxLength (false=include as little as possible)
@@ -480,6 +482,8 @@ class WireTextTools extends Wire {
'noEndSentence' => $this->_('Mr. Mrs. Ms. Dr. Hon. PhD. i.e. e.g.'), // When in sentence type, words that do not end the sentence (space-separated) 'noEndSentence' => $this->_('Mr. Mrs. Ms. Dr. Hon. PhD. i.e. e.g.'), // When in sentence type, words that do not end the sentence (space-separated)
); );
if($ent) __(true, 'entityEncode', $ent);
if(!strlen($str)) return ''; if(!strlen($str)) return '';
if(is_string($options) && ctype_alpha($options)) { if(is_string($options) && ctype_alpha($options)) {
@@ -711,11 +715,13 @@ class WireTextTools extends Wire {
* *
*/ */
public function getPunctuationChars($sentence = false) { public function getPunctuationChars($sentence = false) {
$ent = __(true, 'entityEncode', false);
if($sentence) { if($sentence) {
$s = $this->_('. ? !'); // Sentence ending punctuation characters (must be space-separated) $s = $this->_('. ? !'); // Sentence ending punctuation characters (must be space-separated)
} else { } else {
$s = $this->_(', : . ? ! “ ” „ " -- ( ) [ ] { } « »'); // All punctuation characters (must be space-separated) $s = $this->_(', : . ? ! “ ” „ " -- ( ) [ ] { } « »'); // All punctuation characters (must be space-separated)
} }
if($ent) __(true, 'entityEncode', $ent);
return explode(' ', $s); return explode(' ', $s);
} }