forked from loafle/openapi-generator-original
better filename handling in objectseralizer (php)
This commit is contained in:
parent
3c48202bee
commit
eebf743fad
@ -79,6 +79,23 @@ class ObjectSerializer
|
|||||||
return $sanitized;
|
return $sanitized;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sanitize filename by removing path.
|
||||||
|
* e.g. ../../sun.gif becomes sun.gif
|
||||||
|
*
|
||||||
|
* @param string $filename filename to be sanitized
|
||||||
|
*
|
||||||
|
* @return string the sanitized filename
|
||||||
|
*/
|
||||||
|
public function sanitizeFilename($filename)
|
||||||
|
{
|
||||||
|
if (preg_match("/.*[\/\\\\](.*)$/", $filename, $match)) {
|
||||||
|
return $match[1];
|
||||||
|
} else {
|
||||||
|
return $filename;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Take value and turn it into a string suitable for inclusion in
|
* Take value and turn it into a string suitable for inclusion in
|
||||||
* the path, by url-encoding.
|
* the path, by url-encoding.
|
||||||
@ -232,7 +249,7 @@ class ObjectSerializer
|
|||||||
} elseif ($class === '\SplFileObject') {
|
} elseif ($class === '\SplFileObject') {
|
||||||
// determine file name
|
// determine file name
|
||||||
if (array_key_exists('Content-Disposition', $httpHeaders) && preg_match('/inline; filename=[\'"]?([^\'"\s]+)[\'"]?$/i', $httpHeaders['Content-Disposition'], $match)) {
|
if (array_key_exists('Content-Disposition', $httpHeaders) && preg_match('/inline; filename=[\'"]?([^\'"\s]+)[\'"]?$/i', $httpHeaders['Content-Disposition'], $match)) {
|
||||||
$filename = Configuration::getDefaultConfiguration()->getTempFolderPath().$match[1];
|
$filename = Configuration::getDefaultConfiguration()->getTempFolderPath() . sanitizeFilename($match[1]);
|
||||||
} else {
|
} else {
|
||||||
$filename = tempnam(Configuration::getDefaultConfiguration()->getTempFolderPath(), '');
|
$filename = tempnam(Configuration::getDefaultConfiguration()->getTempFolderPath(), '');
|
||||||
}
|
}
|
||||||
|
@ -79,6 +79,23 @@ class ObjectSerializer
|
|||||||
return $sanitized;
|
return $sanitized;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sanitize filename by removing path.
|
||||||
|
* e.g. ../../sun.gif becomes sun.gif
|
||||||
|
*
|
||||||
|
* @param string $filename filename to be sanitized
|
||||||
|
*
|
||||||
|
* @return string the sanitized filename
|
||||||
|
*/
|
||||||
|
public function sanitizeFilename($filename)
|
||||||
|
{
|
||||||
|
if (preg_match("/.*[\/\\\\](.*)$/", $filename, $match)) {
|
||||||
|
return $match[1];
|
||||||
|
} else {
|
||||||
|
return $filename;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Take value and turn it into a string suitable for inclusion in
|
* Take value and turn it into a string suitable for inclusion in
|
||||||
* the path, by url-encoding.
|
* the path, by url-encoding.
|
||||||
@ -232,7 +249,7 @@ class ObjectSerializer
|
|||||||
} elseif ($class === '\SplFileObject') {
|
} elseif ($class === '\SplFileObject') {
|
||||||
// determine file name
|
// determine file name
|
||||||
if (array_key_exists('Content-Disposition', $httpHeaders) && preg_match('/inline; filename=[\'"]?([^\'"\s]+)[\'"]?$/i', $httpHeaders['Content-Disposition'], $match)) {
|
if (array_key_exists('Content-Disposition', $httpHeaders) && preg_match('/inline; filename=[\'"]?([^\'"\s]+)[\'"]?$/i', $httpHeaders['Content-Disposition'], $match)) {
|
||||||
$filename = Configuration::getDefaultConfiguration()->getTempFolderPath().$match[1];
|
$filename = Configuration::getDefaultConfiguration()->getTempFolderPath() . sanitizeFilename($match[1]);
|
||||||
} else {
|
} else {
|
||||||
$filename = tempnam(Configuration::getDefaultConfiguration()->getTempFolderPath(), '');
|
$filename = tempnam(Configuration::getDefaultConfiguration()->getTempFolderPath(), '');
|
||||||
}
|
}
|
||||||
|
@ -253,7 +253,6 @@ class PetApiTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$this->assertInternalType("int", $get_response['sold']);
|
$this->assertInternalType("int", $get_response['sold']);
|
||||||
$this->assertInternalType("int", $get_response['pending']);
|
$this->assertInternalType("int", $get_response['pending']);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user