Browse Source

Don't treat strings strarting with "@" as file paths.

Fixes #11960.
ADmad 8 years ago
parent
commit
7c84cb2210
2 changed files with 4 additions and 48 deletions
  1. 0 6
      src/Http/Client/FormData.php
  2. 4 42
      tests/TestCase/Http/Client/FormDataTest.php

+ 0 - 6
src/Http/Client/FormData.php

@@ -101,12 +101,6 @@ class FormData implements Countable
             $this->addRecursive($name, $value);
         } elseif (is_resource($value)) {
             $this->addFile($name, $value);
-        } elseif (is_string($value) && strlen($value) && $value[0] === '@') {
-            deprecationWarning(
-                'Using the @ syntax for file uploads is not safe and is deprecated. ' .
-                'Instead you should use file handles.'
-            );
-            $this->addFile($name, $value);
         } elseif ($name instanceof FormDataPart && $value === null) {
             $this->_hasComplexPart = true;
             $this->_parts[] = $name;

+ 4 - 42
tests/TestCase/Http/Client/FormDataTest.php

@@ -60,12 +60,13 @@ class FormDataTest extends TestCase
         $data->add('test', 'value')
             ->add('empty', '')
             ->add('int', 1)
-            ->add('float', 2.3);
+            ->add('float', 2.3)
+            ->add('password', '@secret');
 
-        $this->assertCount(4, $data);
+        $this->assertCount(5, $data);
         $boundary = $data->boundary();
         $result = (string)$data;
-        $expected = 'test=value&empty=&int=1&float=2.3';
+        $expected = 'test=value&empty=&int=1&float=2.3&password=%40secret';
         $this->assertEquals($expected, $result);
     }
 
@@ -142,45 +143,6 @@ class FormDataTest extends TestCase
     /**
      * Test adding a part with a file in it.
      *
-     * @group deprecated
-     * @return void
-     */
-    public function testAddArrayWithFile()
-    {
-        $this->deprecated(function () {
-
-            $file = CORE_PATH . 'VERSION.txt';
-            $contents = file_get_contents($file);
-
-            $data = new FormData();
-            $data->add('Article', [
-                'title' => 'first post',
-                'thumbnail' => '@' . $file
-            ]);
-            $boundary = $data->boundary();
-            $result = (string)$data;
-
-            $expected = [
-                '--' . $boundary,
-                'Content-Disposition: form-data; name="Article[title]"',
-                '',
-                'first post',
-                '--' . $boundary,
-                'Content-Disposition: form-data; name="Article[thumbnail]"; filename="VERSION.txt"',
-                'Content-Type: text/plain; charset=us-ascii',
-                '',
-                $contents,
-                '--' . $boundary . '--',
-                '',
-                '',
-            ];
-            $this->assertEquals(implode("\r\n", $expected), $result);
-        });
-    }
-
-    /**
-     * Test adding a part with a file in it.
-     *
      * @return void
      */
     public function testAddFile()