Fixed bool parsing on multipart form
Change-Id: Ia01d45072468bd90e111fdc5cd8fe3b91555ecb9
This commit is contained in:
parent
c75aa1f10b
commit
b1e8ed9208
|
@ -619,6 +619,7 @@ final class OAuth2PresentationApiController extends OAuth2ProtectedController
|
|||
if (is_null($summit)) return $this->error404();
|
||||
|
||||
$data = $request->all();
|
||||
|
||||
$rules = [
|
||||
'file' => 'required_without:link',
|
||||
'link' => 'required_without:file|url',
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
**/
|
||||
use Closure;
|
||||
use utils\ParseMultiPartFormDataInputStream;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
/**
|
||||
* Class ParseMultipartFormDataInputForNonPostRequests
|
||||
* @package App\Http\Middleware
|
||||
|
@ -36,22 +37,18 @@ final class ParseMultipartFormDataInputForNonPostRequests
|
|||
if (preg_match('/multipart\/form-data/', $request->headers->get('Content-Type')) or
|
||||
preg_match('/multipart\/form-data/', $request->headers->get('content-type'))
|
||||
) {
|
||||
$parser = new ParseMultiPartFormDataInputStream(file_get_contents('php://input'));
|
||||
$params = $parser->getInput();
|
||||
$files = [];
|
||||
$parameters = [];
|
||||
foreach ($params as $key => $param) {
|
||||
if ($param instanceof \Symfony\Component\HttpFoundation\File\UploadedFile) {
|
||||
$files[$key] = $param;
|
||||
} else {
|
||||
$parameters[$key] = $param;
|
||||
}
|
||||
}
|
||||
$parser = new ParseMultiPartFormDataInputStream(file_get_contents('php://input'));
|
||||
$params = $parser->getInput();
|
||||
$data = $params['parameters'];
|
||||
$files = $params['files'];
|
||||
if (count($files) > 0) {
|
||||
Log::debug("ParseMultipartFormDataInputForNonPostRequests: files ".json_encode($files));
|
||||
$request->files->add($files);
|
||||
}
|
||||
if (count($parameters) > 0) {
|
||||
$request->request->add($parameters);
|
||||
|
||||
if (count($data) > 0) {
|
||||
Log::debug("ParseMultipartFormDataInputForNonPostRequests: parameters ".json_encode($data));
|
||||
$request->request->add($data);
|
||||
}
|
||||
}
|
||||
return $next($request);
|
||||
|
|
|
@ -235,16 +235,35 @@ final class ParseMultiPartFormDataInputStream
|
|||
{
|
||||
$string = trim($string);
|
||||
$data = [];
|
||||
if ( preg_match('name=\"([^\"]*)\"[\n|\r]+([^\n\r].*)$', $string, $match) ) {
|
||||
if ( preg_match('/name=\"([^\"]*)\"[\n|\r]+([^\n\r].*)$/s', $string, $match) ) {
|
||||
$val = ($match[2] !== NULL ? $match[2] : '');
|
||||
if(!empty($val) && is_bool($val))
|
||||
$val = boolval($val);
|
||||
if(!empty($val) && is_string($val) && self::checkBool($val))
|
||||
$val = self::boolVal($val);
|
||||
if(!empty($val) && is_int($val))
|
||||
$val = intval($val);
|
||||
if(!empty($val) && is_double($val))
|
||||
$val = doubleval($val);
|
||||
if (preg_match('/^(.*)\[\]$/i', $match[1], $tmp)) {
|
||||
$data[$tmp[1]][] = ($match[2] !== NULL ? $match[2] : '');
|
||||
$data[$tmp[1]][] = $val;
|
||||
} else {
|
||||
$data[$match[1]] = ($match[2] !== NULL ? $match[2] : '');
|
||||
$data[$match[1]] = $val;
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
static function checkBool($string){
|
||||
$string = strtolower($string);
|
||||
return (in_array($string, array("true", "false", "1", "0", "yes", "no"), true));
|
||||
}
|
||||
|
||||
static function boolVal($string){
|
||||
$string = strtolower($string);
|
||||
if(in_array($string, ["true", "1", "yes"])) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @function merge
|
||||
|
|
Loading…
Reference in New Issue