diff options
Diffstat (limited to 'vendor/sabre/vobject/lib/Property/Text.php')
-rw-r--r-- | vendor/sabre/vobject/lib/Property/Text.php | 45 |
1 files changed, 22 insertions, 23 deletions
diff --git a/vendor/sabre/vobject/lib/Property/Text.php b/vendor/sabre/vobject/lib/Property/Text.php index bb7ab34ee..47a86ccc9 100644 --- a/vendor/sabre/vobject/lib/Property/Text.php +++ b/vendor/sabre/vobject/lib/Property/Text.php @@ -213,16 +213,16 @@ class Text extends Property { $val = $this->getParts(); if (isset($this->minimumPropertyValues[$this->name])) { - $val = array_pad($val, $this->minimumPropertyValues[$this->name], ''); + $val = \array_pad($val, $this->minimumPropertyValues[$this->name], ''); } // Imploding multiple parts into a single value, and splitting the // values with ;. - if (count($val) > 1) { + if (\count($val) > 1) { foreach ($val as $k => $v) { - $val[$k] = str_replace(';', '\;', $v); + $val[$k] = \str_replace(';', '\;', $v); } - $val = implode(';', $val); + $val = \implode(';', $val); } else { $val = $val[0]; } @@ -242,7 +242,7 @@ class Text extends Property { // If the resulting value contains a \n, we must encode it as // quoted-printable. - if (strpos($val, "\n") !== false) { + if (\strpos($val, "\n") !== false) { $str .= ';ENCODING=QUOTED-PRINTABLE:'; $lastLine = $str; @@ -252,40 +252,39 @@ class Text extends Property { // encode newlines for us. Specifically, the \r\n sequence must in // vcards be encoded as =0D=OA and we must insert soft-newlines // every 75 bytes. - for ($ii = 0;$ii < strlen($val);$ii++) { - $ord = ord($val[$ii]); + for ($ii = 0;$ii < \strlen($val);$ii++) { + $ord = \ord($val[$ii]); // These characters are encoded as themselves. if ($ord >= 32 && $ord <= 126) { $lastLine .= $val[$ii]; } else { - $lastLine .= '=' . strtoupper(bin2hex($val[$ii])); + $lastLine .= '=' . \strtoupper(\bin2hex($val[$ii])); } - if (strlen($lastLine) >= 75) { + if (\strlen($lastLine) >= 75) { // Soft line break $out .= $lastLine . "=\r\n "; $lastLine = null; } } - if (!is_null($lastLine)) $out .= $lastLine . "\r\n"; + if (!\is_null($lastLine)) $out .= $lastLine . "\r\n"; return $out; } else { $str .= ':' . $val; - $out = ''; - while (strlen($str) > 0) { - if (strlen($str) > 75) { - $part = mb_strcut($str, 0, 75, 'utf-8'); - $out .= $part . "\r\n"; - $str = ' ' . substr($str, strlen($part)); - } else { - $out .= $str . "\r\n"; - $str = ''; - break; - } - } - return $out; + $str = \preg_replace( + '/( + (?:^.)? # 1 additional byte in first line because of missing single space (see next line) + .{1,74} # max 75 bytes per line (1 byte is used for a single space added after every CRLF) + (?![\x80-\xbf]) # prevent splitting multibyte characters + )/x', + "$1\r\n ", + $str + ); + + // remove single space after last CRLF + return \substr($str, 0, -1); } |