Skip to content

Commit 70edac8

Browse files
committed
Removed references for mb_*
- Removed the multibyte management for the strings, because with empty PDFs and DOCX does not find the boundary string correctly.
1 parent 9f4f476 commit 70edac8

2 files changed

Lines changed: 16 additions & 16 deletions

File tree

src/Http/MultipartParser.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ private static function iniSizeToBytes(string $size): int|float
120120
return (int) $size;
121121
}
122122

123-
$suffix = mb_strtoupper(mb_substr($size, -1));
124-
$strippedSize = mb_substr($size, 0, -1);
123+
$suffix = strtoupper(substr($size, -1));
124+
$strippedSize = substr($size, 0, -1);
125125

126126
if (! is_numeric($strippedSize)) {
127127
throw new InvalidArgumentException("$size is not a valid ini size");
@@ -149,22 +149,22 @@ private static function iniSizeToBytes(string $size): int|float
149149

150150
private function parseBody(string $boundary, string $buffer): void
151151
{
152-
$len = mb_strlen($boundary);
152+
$len = strlen($boundary);
153153

154154
// ignore everything before initial boundary (SHOULD be empty)
155-
$this->cursor = mb_strpos($buffer, $boundary."\r\n");
155+
$this->cursor = strpos($buffer, $boundary."\r\n");
156156

157157
while ($this->cursor !== false) {
158158
// search following boundary (preceded by newline)
159159
// ignore last if not followed by boundary (SHOULD end with "--")
160160
$this->cursor += $len + 2;
161-
$end = mb_strpos($buffer, "\r\n".$boundary, $this->cursor);
161+
$end = strpos($buffer, "\r\n".$boundary, $this->cursor);
162162
if ($end === false) {
163163
break;
164164
}
165165

166166
// parse one part and continue searching for next
167-
$this->parsePart(mb_substr($buffer, $this->cursor, $end - $this->cursor));
167+
$this->parsePart(substr($buffer, $this->cursor, $end - $this->cursor));
168168
$this->cursor = $end;
169169

170170
if (++$this->multipartBodyPartCount > $this->maxMultipartBodyParts) {
@@ -175,13 +175,13 @@ private function parseBody(string $boundary, string $buffer): void
175175

176176
private function parsePart(string $chunk): void
177177
{
178-
$pos = mb_strpos($chunk, "\r\n\r\n");
178+
$pos = strpos($chunk, "\r\n\r\n");
179179
if ($pos === false) {
180180
return;
181181
}
182182

183-
$headers = $this->parseHeaders(mb_substr($chunk, 0, $pos));
184-
$body = mb_substr($chunk, $pos + 4);
183+
$headers = $this->parseHeaders(substr($chunk, 0, $pos));
184+
$body = substr($chunk, $pos + 4);
185185

186186
if (! isset($headers['content-disposition'])) {
187187
return;
@@ -221,7 +221,7 @@ private function parseFile(string $name, string $filename, ?string $contentType,
221221

222222
private function parseUploadedFile(string $filename, ?string $contentType, string $contents): ?UploadedFile
223223
{
224-
$size = mb_strlen($contents);
224+
$size = strlen($contents);
225225
$tempFileName = tempnam(sys_get_temp_dir(), 'PHP_UPLOAD_FILE_');
226226

227227
// no file selected (zero size and empty filename)
@@ -291,7 +291,7 @@ private function parsePost(string $name, string $value): void
291291
$value
292292
);
293293

294-
if (mb_strtoupper($name) === 'MAX_FILE_SIZE') {
294+
if (strtoupper($name) === 'MAX_FILE_SIZE') {
295295
$this->maxFileSize = (int) $value;
296296

297297
if ($this->maxFileSize === 0) {
@@ -307,13 +307,13 @@ private function parseHeaders(string $header): array
307307
{
308308
$headers = [];
309309

310-
foreach (explode("\r\n", mb_trim($header)) as $line) {
310+
foreach (explode("\r\n", trim($header)) as $line) {
311311
$parts = explode(':', $line, 2);
312312
if (! isset($parts[1])) {
313313
continue;
314314
}
315315

316-
$key = mb_strtolower(mb_trim($parts[0]));
316+
$key = strtolower(trim($parts[0]));
317317
$values = explode(';', $parts[1]);
318318
$values = array_map('trim', $values);
319319
$headers[$key] = $values;
@@ -357,7 +357,7 @@ private function extractPost(array $postFields, string $key, mixed $value): arra
357357
return $postFields;
358358
}
359359

360-
$chunkKey = mb_rtrim($chunks[0], ']');
360+
$chunkKey = rtrim($chunks[0], ']');
361361
$parent = &$postFields;
362362
for ($i = 1; isset($chunks[$i]); $i++) {
363363
$previousChunkKey = $chunkKey;
@@ -378,7 +378,7 @@ private function extractPost(array $postFields, string $key, mixed $value): arra
378378
$parent = &$parent[$previousChunkKey];
379379
}
380380

381-
$chunkKey = mb_rtrim($chunks[$i], ']');
381+
$chunkKey = rtrim($chunks[$i], ']');
382382
}
383383

384384
if ($chunkKey === '') {

src/Http/RequestBodyParser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function __construct(?string $uploadMaxFilesize = null, ?int $maxFileUplo
2626
*/
2727
public function parseForm(AmpRequest $request, string $body): array
2828
{
29-
$type = mb_strtolower($request->getHeader('Content-Type') ?? '');
29+
$type = strtolower($request->getHeader('Content-Type') ?? '');
3030
[$type] = explode(';', $type);
3131

3232
if ($type === 'application/x-www-form-urlencoded') {

0 commit comments

Comments
 (0)