Unverified Commit e6945765 authored by Alex Pott's avatar Alex Pott
Browse files

task: #3588024 PHP 8.6 - Functions mb_regex_encoding() and mb_ereg() are deprecated

By: mondrake
By: dww
By: godotislate
By: alexpott
By: andypost
parent a85f1db8
Loading
Loading
Loading
Loading
Loading
+3 −10
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@

use Drupal\Component\Utility\Html;
use Drupal\Component\Render\MarkupInterface;
use Drupal\Component\Utility\Unicode;
use Drupal\Component\Utility\UrlHelper;
use Drupal\Component\Utility\Xss;
use Drupal\Core\Form\FormStateInterface;
@@ -1871,17 +1872,9 @@ public static function trimText($alter, $value) {
    if (mb_strlen($value) > $alter['max_length']) {
      $value = mb_substr($value, 0, $alter['max_length']);
      if (!empty($alter['word_boundary'])) {
        $regex = "(.*)\b.+";
        if (function_exists('mb_ereg')) {
          mb_regex_encoding('UTF-8');
          $found = mb_ereg($regex, $value, $matches);
        }
        else {
        $regex = '(.*)(?=[' . Unicode::PREG_CLASS_WORD_BOUNDARY . ']).+';
        $found = preg_match("/$regex/us", $value, $matches);
        }
        if ($found) {
          $value = $matches[1];
        }
        $value = $found ? $matches[1] : '';
      }
      // Remove scraps of HTML entities from the end of a strings.
      $value = rtrim(preg_replace('/(?:<(?!.+>)|&(?!.+;)).*$/us', '', $value));
+3 −0
Original line number Diff line number Diff line
@@ -795,6 +795,7 @@ public function testTrimText(): void {
      'của hãng bao gồm ba dòng',
      'сд асд асд ас',
      'асд асд асд ас',
      'हिंदी परीक्षण स्ट्रिंग',
    ];
    // Just test maxlength without word boundary.
    $alter = [
@@ -809,6 +810,7 @@ public function testTrimText(): void {
      'của hãng b',
      'сд асд асд',
      'асд асд ас',
      'हिंदी परीक',
    ];

    foreach ($text as $key => $line) {
@@ -827,6 +829,7 @@ public function testTrimText(): void {
      'của hãng',
      'сд асд',
      'асд асд',
      'हिंदी',
    ];

    foreach ($text as $key => $line) {