Skip to content

Commit

Permalink
Fixed multibyte string encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
edgardmessias authored Jan 14, 2021
1 parent c1f2125 commit 87d737b
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/Header/ContentDisposition.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,21 @@ public function getFieldValue($format = HeaderInterface::FORMAT_RAW)
$maxValueLength -= ($encodedLength - $decodedLength);
}

$valueParts = str_split($value, $maxValueLength);
if (function_exists('mb_str_split')) {
// mbstring and PHP >= 7.4
$valueParts = mb_str_split($value, $maxValueLength);
} elseif (function_exists('mb_strlen') && function_exists('mb_strlen')) {
// mbstring and PHP < 7.4
$valueParts = [];
$length = mb_strlen($value);
for ($i = 0; $i < $length; $i += $maxValueLength) {
$valueParts[] = mb_substr($value, $i, $maxValueLength);
}
} else {
// Fallback
$valueParts = str_split($value, $maxValueLength);
}

$i = 0;
foreach ($valueParts as $valuePart) {
$attributePart = $attribute . '*' . $i++;
Expand Down

0 comments on commit 87d737b

Please sign in to comment.