Skip to content

Commit 14cb0cb

Browse files
Merge branch '6.4' into 7.2
* 6.4: [WebProfilerBundle] Fix tests [Cache] Tests for Redis Replication with cache [BrowserKit] Fix submitting forms with empty file fields [WebProfilerBundle] Fix interception for non conventional redirects [DependencyInjection] Do not preload functions [DependencyInjection] Fix cloned lazy services not sharing their dependencies when dumped with PhpDumper [HttpClient] Fix activity tracking leading to negative timeout errors [Security] Return null instead of empty username to fix deprecation notice [DependencyInjection] Fix env default processor with scalar node
2 parents 8d64d17 + 0c806f2 commit 14cb0cb

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

HttpBrowser.php

+7-2
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,15 @@ private function getUploadedFiles(array $files): array
145145
}
146146
if (!isset($file['tmp_name'])) {
147147
$uploadedFiles[$name] = $this->getUploadedFiles($file);
148+
continue;
148149
}
149-
if (isset($file['tmp_name'])) {
150-
$uploadedFiles[$name] = DataPart::fromPath($file['tmp_name'], $file['name']);
150+
151+
if ('' === $file['tmp_name']) {
152+
$uploadedFiles[$name] = new DataPart('', '');
153+
continue;
151154
}
155+
156+
$uploadedFiles[$name] = DataPart::fromPath($file['tmp_name'], $file['name']);
152157
}
153158

154159
return $uploadedFiles;

Tests/HttpBrowserTest.php

+33
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
use Symfony\Component\BrowserKit\CookieJar;
1515
use Symfony\Component\BrowserKit\History;
1616
use Symfony\Component\BrowserKit\HttpBrowser;
17+
use Symfony\Component\HttpClient\MockHttpClient;
18+
use Symfony\Component\HttpClient\Response\MockResponse;
1719
use Symfony\Contracts\HttpClient\HttpClientInterface;
1820
use Symfony\Contracts\HttpClient\ResponseInterface;
1921

@@ -208,6 +210,37 @@ public static function forwardSlashesRequestPathProvider()
208210
];
209211
}
210212

213+
public function testEmptyUpload()
214+
{
215+
$client = new MockHttpClient(function ($method, $url, $options) {
216+
$this->assertSame('POST', $method);
217+
$this->assertSame('http://localhost/', $url);
218+
$this->assertStringStartsWith('Content-Type: multipart/form-data; boundary=', $options['normalized_headers']['content-type'][0]);
219+
220+
$body = '';
221+
while ('' !== $data = $options['body'](1024)) {
222+
$body .= $data;
223+
}
224+
225+
$expected = <<<EOTXT
226+
--%s\r
227+
Content-Type: application/octet-stream\r
228+
Content-Transfer-Encoding: 8bit\r
229+
Content-Disposition: form-data; name="file"; filename=""\r
230+
\r
231+
\r
232+
--%s--\r
233+
234+
EOTXT;
235+
$this->assertStringMatchesFormat($expected, $body);
236+
237+
return new MockResponse();
238+
});
239+
240+
$browser = new HttpBrowser($client);
241+
$browser->request('POST', '/', [], ['file' => ['tmp_name' => '', 'name' => 'file']]);
242+
}
243+
211244
private function uploadFile(string $data): string
212245
{
213246
$path = tempnam(sys_get_temp_dir(), 'http');

0 commit comments

Comments
 (0)