Fix on multiresponse parser

Change-Id: Iee98d42e880a6dd40fb911366096f2892751f010
This commit is contained in:
Sebastian Marcet 2018-03-14 20:23:47 -03:00
parent fba29fb43c
commit 00edd5a7e3
3 changed files with 52 additions and 16 deletions

View File

@ -1942,11 +1942,11 @@ final class OAuth2SummitLocationsApiController extends OAuth2ProtectedController
if(!strstr($content_type, 'multipart/form-data'))
return $this->error400();
$multiPartRequestParser = new ParseMultiPartFormDataInputStream();
$input = $multiPartRequestParser->getInput();
$metadata = $input['parameters'];
$files = $input['files'];
$file = null;
$parser = new ParseMultiPartFormDataInputStream(file_get_contents('php://input'));
$input = $parser->getInput();
$metadata = $input['parameters'];
$files = $input['files'];
$file = null;
if(isset($files['file']))
$file = $files['file'];
@ -2158,11 +2158,11 @@ final class OAuth2SummitLocationsApiController extends OAuth2ProtectedController
if(!strstr($content_type, 'multipart/form-data'))
return $this->error400();
$multiPartRequestParser = new ParseMultiPartFormDataInputStream();
$input = $multiPartRequestParser->getInput();
$metadata = $input['parameters'];
$files = $input['files'];
$file = null;
$parser = new ParseMultiPartFormDataInputStream(file_get_contents('php://input'));
$input = $parser->getInput();
$metadata = $input['parameters'];
$files = $input['files'];
$file = null;
if(isset($files['file']))
$file = $files['file'];

View File

@ -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] : '');
}
}

View File

@ -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();
}
}