diff options
author | kondou <kondou@ts.unde.re> | 2013-07-30 16:09:54 +0200 |
---|---|---|
committer | kondou <kondou@ts.unde.re> | 2013-08-25 21:04:09 +0200 |
commit | 2bfe66223563b16a067be273e0d6979b420598ad (patch) | |
tree | dbe49438dc9c2175895eedb442e9e1630bc01b67 /lib | |
parent | fac671b14ed06233d37ad38194ebf9a99118644a (diff) | |
download | nextcloud-server-2bfe66223563b16a067be273e0d6979b420598ad.tar.gz nextcloud-server-2bfe66223563b16a067be273e0d6979b420598ad.zip |
Add unittests & check filetype in setLocalAvatar()
TODO: Fix OC_Image->mimetype(), it always returns "image/png"
Diffstat (limited to 'lib')
-rw-r--r-- | lib/avatar.php | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/lib/avatar.php b/lib/avatar.php index b232e9be762..f3db07142ca 100644 --- a/lib/avatar.php +++ b/lib/avatar.php @@ -43,11 +43,11 @@ class OC_Avatar { * @brief sets the users local avatar * @param $user string user to set the avatar for * @param $img mixed imagedata to set a new avatar, or false to delete the current avatar - * @param $type string fileextension + * @throws Exception if the provided file is not a jpg or png image * @throws Exception if the provided image is not valid, or not a square * @return true on success */ - public static function setLocalAvatar ($user, $img, $type) { + public static function setLocalAvatar ($user, $img) { $view = new \OC\Files\View('/'.$user); if ($img === false) { @@ -56,6 +56,12 @@ class OC_Avatar { return true; } else { $img = new OC_Image($img); + // FIXME this always says "image/png" + $type = substr($img->mimeType(), -3); + if ($type === 'peg') { $type = 'jpg'; } + if ($type !== 'jpg' && $type !== 'png') { + throw new Exception(); + } if (!( $img->valid() && ($img->height() === $img->width()) )) { throw new Exception(); |