From 60594d53311362e8c1434734b7ab7f070b594584 Mon Sep 17 00:00:00 2001 From: Zach Borboa Date: Tue, 27 Oct 2015 23:04:32 -0700 Subject: [PATCH] Fix #258: Allow sending request data with non-file values prefixed with the @ character --- src/Curl/Curl.php | 12 +++++------- tests/PHPCurlClass/PHPCurlClassTest.php | 11 +++++++++++ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/Curl/Curl.php b/src/Curl/Curl.php index 902924c..f4e94b4 100644 --- a/src/Curl/Curl.php +++ b/src/Curl/Curl.php @@ -105,15 +105,13 @@ class Curl } else { $binary_data = false; foreach ($data as $key => $value) { - // Fix "Notice: Array to string conversion" when $value in - // curl_setopt($ch, CURLOPT_POSTFIELDS, $value) is an array - // that contains an empty array. + // Fix "Notice: Array to string conversion" when $value in curl_setopt($ch, CURLOPT_POSTFIELDS, + // $value) is an array that contains an empty array. if (is_array($value) && empty($value)) { $data[$key] = ''; - // Fix "curl_setopt(): The usage of the @filename API for - // file uploading is deprecated. Please use the CURLFile - // class instead". - } elseif (is_string($value) && strpos($value, '@') === 0) { + // Fix "curl_setopt(): The usage of the @filename API for file uploading is deprecated. Please use + // the CURLFile class instead". Ignore non-file values prefixed with the @ character. + } elseif (is_string($value) && strpos($value, '@') === 0 && is_file(substr($value, 1))) { $binary_data = true; if (class_exists('CURLFile')) { $data[$key] = new \CURLFile(substr($value, 1)); diff --git a/tests/PHPCurlClass/PHPCurlClassTest.php b/tests/PHPCurlClass/PHPCurlClassTest.php index 3072b51..e762118 100644 --- a/tests/PHPCurlClass/PHPCurlClassTest.php +++ b/tests/PHPCurlClass/PHPCurlClassTest.php @@ -385,6 +385,17 @@ class CurlTest extends PHPUnit_Framework_TestCase } } + public function testPostNonFilePathUpload() + { + $test = new Test(); + $test->server('post', 'POST', array( + 'foo' => 'bar', + 'file' => '@not-a-file', + )); + $this->assertFalse($test->curl->error); + $this->assertEquals('foo=bar&file=%40not-a-file', $test->curl->response); + } + public function testPutRequestMethod() { $test = new Test();