Security update for Core, with self-updated composer
[yaffs-website] / web / core / lib / Drupal / Component / Utility / Unicode.php
index 98db80431c7e4eead5f9c8f3744c504afb81ddf0..f8e026faf69c3fb7deff6fbb482587fd068a6f6c 100644 (file)
@@ -264,7 +264,9 @@ EOD;
       return substr($string, 0, $len);
     }
     // Scan backwards to beginning of the byte sequence.
-    while (--$len >= 0 && ord($string[$len]) >= 0x80 && ord($string[$len]) < 0xC0);
+    // @todo Make the code more readable in https://www.drupal.org/node/2911497.
+    while (--$len >= 0 && ord($string[$len]) >= 0x80 && ord($string[$len]) < 0xC0) {
+    }
 
     return substr($string, 0, $len);
   }
@@ -376,7 +378,7 @@ EOD;
    */
   public static function ucwords($text) {
     $regex = '/(^|[' . static::PREG_CLASS_WORD_BOUNDARY . '])([^' . static::PREG_CLASS_WORD_BOUNDARY . '])/u';
-    return preg_replace_callback($regex, function(array $matches) {
+    return preg_replace_callback($regex, function (array $matches) {
       return $matches[1] . Unicode::strtoupper($matches[2]);
     }, $text);
   }
@@ -580,7 +582,7 @@ EOD;
    *   Returns < 0 if $str1 is less than $str2; > 0 if $str1 is greater than
    *   $str2, and 0 if they are equal.
    */
-  public static function strcasecmp($str1 , $str2) {
+  public static function strcasecmp($str1, $str2) {
     return strcmp(static::strtoupper($str1), static::strtoupper($str2));
   }
 
@@ -601,18 +603,24 @@ EOD;
    *
    * @param string $string
    *   The header to encode.
+   * @param bool $shorten
+   *   If TRUE, only return the first chunk of a multi-chunk encoded string.
    *
    * @return string
    *   The mime-encoded header.
    */
-  public static function mimeHeaderEncode($string) {
+  public static function mimeHeaderEncode($string, $shorten = FALSE) {
     if (preg_match('/[^\x20-\x7E]/', $string)) {
-      $chunk_size = 47; // floor((75 - strlen("=?UTF-8?B??=")) * 0.75);
+      // floor((75 - strlen("=?UTF-8?B??=")) * 0.75);
+      $chunk_size = 47;
       $len = strlen($string);
       $output = '';
       while ($len > 0) {
         $chunk = static::truncateBytes($string, $chunk_size);
         $output .= ' =?UTF-8?B?' . base64_encode($chunk) . "?=\n";
+        if ($shorten) {
+          break;
+        }
         $c = strlen($chunk);
         $string = substr($string, $c);
         $len -= $c;