Merge branch 'master' into dependabot/npm_and_yarn/mixin-deep-1.3.2

This commit is contained in:
Nicolas Maillat
2019-11-08 17:45:18 +01:00
committed by GitHub
2 changed files with 23 additions and 0 deletions

View File

@@ -63,4 +63,26 @@ class StringUtils
return self::$transliterator->transliterate($string);
}
/**
* replace bad chars (ascii 0...31 except 9,10,13)
*
* @param $s
* @param string $replace
* @return mixed
*/
public static function substituteCtrlCharacters($s, $replace = '_')
{
static $bad_chars = null;
if($bad_chars === null) {
$bad_chars = [];
for($i=0; $i<32; $i++) {
if($i != 9 && $i != 10 && $i != 13) {
$bad_chars[] = chr($i);
}
}
}
return str_replace($bad_chars, $replace, $s);
}
}

View File

@@ -32,6 +32,7 @@ class CandidateTerms
public function insert($field, $value)
{
$value = StringUtils::substituteCtrlCharacters($value, '');
$this->ensureVisitorSetup();
if (!$this->visitor->hasTerm($field, $value)) {
$this->new_candidates[$value] = $field;