More specific exceptions for mimetype/extension issues.
This commit is contained in:
parent
b4a0bff740
commit
4117118e23
26
lib/unknownextensionmimeexception.php
Normal file
26
lib/unknownextensionmimeexception.php
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
if (!defined('GNUSOCIAL')) { exit(1); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class for unknown extension MIME type exception
|
||||||
|
*
|
||||||
|
* Thrown when we don't know the MIME type for a given file extension.
|
||||||
|
*
|
||||||
|
* @category Exception
|
||||||
|
* @package GNUsocial
|
||||||
|
* @author Mikael Nordfeldth <mmn@hethane.se>
|
||||||
|
* @license https://www.gnu.org/licenses/agpl-3.0.html
|
||||||
|
* @link https://gnu.io/social
|
||||||
|
*/
|
||||||
|
|
||||||
|
class UnknownExtensionMimeException extends ServerException
|
||||||
|
{
|
||||||
|
public function __construct($ext)
|
||||||
|
{
|
||||||
|
// TRANS: We accept the file type (we probably just accept all files)
|
||||||
|
// TRANS: but don't know the file extension for it. %1$s is the extension.
|
||||||
|
$msg = sprintf(_('Unknown MIME type for file extension: %1$s'), _ve($ext));
|
||||||
|
|
||||||
|
parent::__construct($msg);
|
||||||
|
}
|
||||||
|
}
|
@ -17,14 +17,11 @@ if (!defined('GNUSOCIAL')) { exit(1); }
|
|||||||
|
|
||||||
class UnknownMimeExtensionException extends ServerException
|
class UnknownMimeExtensionException extends ServerException
|
||||||
{
|
{
|
||||||
public function __construct($msg=null)
|
public function __construct($mimetype)
|
||||||
{
|
{
|
||||||
if ($msg === null) {
|
|
||||||
// TRANS: We accept the file type (we probably just accept all files)
|
// TRANS: We accept the file type (we probably just accept all files)
|
||||||
// TRANS: but don't know the file extension for it.
|
// TRANS: but don't know the file extension for it.
|
||||||
$msg = _('Supported mimetype but unknown extension relation.');
|
$msg = sprintf(_('Supported mimetype but unknown extension relation: %1$s'), _ve($mimetype));
|
||||||
}
|
|
||||||
|
|
||||||
parent::__construct($msg);
|
parent::__construct($msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2000,7 +2000,7 @@ function common_supported_ext_to_mime($fileext)
|
|||||||
|
|
||||||
$supported = common_config('attachments', 'supported');
|
$supported = common_config('attachments', 'supported');
|
||||||
if ($supported === true) {
|
if ($supported === true) {
|
||||||
throw new ServerException('Supported extension but unknown mimetype relation.');
|
throw new UnknownExtensionMimeException($fileext);
|
||||||
}
|
}
|
||||||
foreach($supported as $type => $ext) {
|
foreach($supported as $type => $ext) {
|
||||||
if ($ext === $fileext) {
|
if ($ext === $fileext) {
|
||||||
@ -2016,7 +2016,7 @@ function common_supported_mime_to_ext($mimetype)
|
|||||||
{
|
{
|
||||||
$supported = common_config('attachments', 'supported');
|
$supported = common_config('attachments', 'supported');
|
||||||
if ($supported === true) {
|
if ($supported === true) {
|
||||||
throw new UnknownMimeExtensionException();
|
throw new UnknownMimeExtensionException($mimetype);
|
||||||
}
|
}
|
||||||
foreach($supported as $type => $ext) {
|
foreach($supported as $type => $ext) {
|
||||||
if ($mimetype === $type) {
|
if ($mimetype === $type) {
|
||||||
|
Loading…
Reference in New Issue
Block a user