Skip to content
This repository was archived by the owner on Sep 22, 2022. It is now read-only.

Commit 60594d5

Browse files
committed
Fix php-curl-class#258: Allow sending request data with non-file values prefixed with the @ character
1 parent 18afb20 commit 60594d5

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

src/Curl/Curl.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,13 @@ public function buildPostData($data)
105105
} else {
106106
$binary_data = false;
107107
foreach ($data as $key => $value) {
108-
// Fix "Notice: Array to string conversion" when $value in
109-
// curl_setopt($ch, CURLOPT_POSTFIELDS, $value) is an array
110-
// that contains an empty array.
108+
// Fix "Notice: Array to string conversion" when $value in curl_setopt($ch, CURLOPT_POSTFIELDS,
109+
// $value) is an array that contains an empty array.
111110
if (is_array($value) && empty($value)) {
112111
$data[$key] = '';
113-
// Fix "curl_setopt(): The usage of the @filename API for
114-
// file uploading is deprecated. Please use the CURLFile
115-
// class instead".
116-
} elseif (is_string($value) && strpos($value, '@') === 0) {
112+
// Fix "curl_setopt(): The usage of the @filename API for file uploading is deprecated. Please use
113+
// the CURLFile class instead". Ignore non-file values prefixed with the @ character.
114+
} elseif (is_string($value) && strpos($value, '@') === 0 && is_file(substr($value, 1))) {
117115
$binary_data = true;
118116
if (class_exists('CURLFile')) {
119117
$data[$key] = new \CURLFile(substr($value, 1));

tests/PHPCurlClass/PHPCurlClassTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,17 @@ public function testPostCurlFileUpload()
385385
}
386386
}
387387

388+
public function testPostNonFilePathUpload()
389+
{
390+
$test = new Test();
391+
$test->server('post', 'POST', array(
392+
'foo' => 'bar',
393+
'file' => '@not-a-file',
394+
));
395+
$this->assertFalse($test->curl->error);
396+
$this->assertEquals('foo=bar&file=%40not-a-file', $test->curl->response);
397+
}
398+
388399
public function testPutRequestMethod()
389400
{
390401
$test = new Test();

0 commit comments

Comments
 (0)