Fix on multiresponse parser
Change-Id: Iee98d42e880a6dd40fb911366096f2892751f010
This commit is contained in:
parent
fba29fb43c
commit
00edd5a7e3
|
@ -1942,8 +1942,8 @@ final class OAuth2SummitLocationsApiController extends OAuth2ProtectedController
|
|||
if(!strstr($content_type, 'multipart/form-data'))
|
||||
return $this->error400();
|
||||
|
||||
$multiPartRequestParser = new ParseMultiPartFormDataInputStream();
|
||||
$input = $multiPartRequestParser->getInput();
|
||||
$parser = new ParseMultiPartFormDataInputStream(file_get_contents('php://input'));
|
||||
$input = $parser->getInput();
|
||||
$metadata = $input['parameters'];
|
||||
$files = $input['files'];
|
||||
$file = null;
|
||||
|
@ -2158,8 +2158,8 @@ final class OAuth2SummitLocationsApiController extends OAuth2ProtectedController
|
|||
if(!strstr($content_type, 'multipart/form-data'))
|
||||
return $this->error400();
|
||||
|
||||
$multiPartRequestParser = new ParseMultiPartFormDataInputStream();
|
||||
$input = $multiPartRequestParser->getInput();
|
||||
$parser = new ParseMultiPartFormDataInputStream(file_get_contents('php://input'));
|
||||
$input = $parser->getInput();
|
||||
$metadata = $input['parameters'];
|
||||
$files = $input['files'];
|
||||
$file = null;
|
||||
|
|
|
@ -25,12 +25,12 @@ final class ParseMultiPartFormDataInputStream
|
|||
protected $input;
|
||||
|
||||
/**
|
||||
* @function __construct
|
||||
*
|
||||
* ParseMultiPartFormDataInputStream constructor.
|
||||
* @param $input
|
||||
*/
|
||||
public function __construct()
|
||||
public function __construct($input)
|
||||
{
|
||||
$this->input = file_get_contents('php://input');
|
||||
$this->input = $input;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -234,12 +234,14 @@ final class ParseMultiPartFormDataInputStream
|
|||
private function parameter($string)
|
||||
{
|
||||
$data = [];
|
||||
$string = trim($string);
|
||||
if(empty($string)) return $data;
|
||||
|
||||
if ( preg_match('/name=\"([^\"]*)\"[\n|\r]+([^\n\r].*)?\r$/s', $string, $match) ) {
|
||||
if (preg_match('/^(.*)\[\]$/i', $match[1], $tmp)) {
|
||||
$data[$tmp[1]][] = ($match[2] !== NULL ? $match[2] : '');
|
||||
$data[$tmp[1]][] = (count($match) >=2 && $match[2] !== NULL ? $match[2] : '');
|
||||
} else {
|
||||
$data[$match[1]] = ($match[2] !== NULL ? $match[2] : '');
|
||||
$data[$match[1]] = (count($match) >=2 && $match[2] !== NULL ? $match[2] : '');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
/**
|
||||
* Copyright 2018 OpenStack Foundation
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
**/
|
||||
|
||||
class ParseMultiPartFormDataInputStreamTest extends TestCase
|
||||
{
|
||||
public function testParse(){
|
||||
$input = <<<DATA
|
||||
------WebKitFormBoundaryRlOdocoDcLqHoxXW
|
||||
Content-Disposition: form-data; name="file"
|
||||
|
||||
|
||||
------WebKitFormBoundaryRlOdocoDcLqHoxXW--
|
||||
|
||||
|
||||
DATA;
|
||||
$_SERVER['CONTENT_TYPE'] = 'multipart/form-data; boundary=----WebKitFormBoundaryRlOdocoDcLqHoxXW';
|
||||
$parser = new \utils\ParseMultiPartFormDataInputStream($input);
|
||||
|
||||
$res = $parser->getInput();
|
||||
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue