diff options
author | Arthur Schiwon <blizzz@owncloud.com> | 2016-02-09 03:14:30 +0100 |
---|---|---|
committer | Arthur Schiwon <blizzz@owncloud.com> | 2016-02-09 03:14:30 +0100 |
commit | 347ad3e223e2582124d56b0d7174886bde194c16 (patch) | |
tree | 8f8d508d1d78a6258eb14c46a457e9bc634631b4 /lib | |
parent | 850ac0cf84f2492b16204b811f58a0dc7dc43b6e (diff) | |
download | nextcloud-server-347ad3e223e2582124d56b0d7174886bde194c16.tar.gz nextcloud-server-347ad3e223e2582124d56b0d7174886bde194c16.zip |
Limit comment message to 1k chars
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/comments/comment.php | 8 | ||||
-rw-r--r-- | lib/public/comments/icomment.php | 5 | ||||
-rw-r--r-- | lib/public/comments/messagetoolongexception.php | 27 |
3 files changed, 39 insertions, 1 deletions
diff --git a/lib/private/comments/comment.php b/lib/private/comments/comment.php index 36189d9523b..27e63c98555 100644 --- a/lib/private/comments/comment.php +++ b/lib/private/comments/comment.php @@ -22,6 +22,7 @@ namespace OC\Comments; use OCP\Comments\IComment; use OCP\Comments\IllegalIDChangeException; +use OCP\Comments\MessageTooLongException; class Comment implements IComment { @@ -184,13 +185,18 @@ class Comment implements IComment { * * @param string $message * @return IComment + * @throws MessageTooLongException * @since 9.0.0 */ public function setMessage($message) { if(!is_string($message)) { throw new \InvalidArgumentException('String expected.'); } - $this->data['message'] = trim($message); + $message = trim($message); + if(mb_strlen($message, 'UTF-8') > IComment::MAX_MESSAGE_LENGTH) { + throw new MessageTooLongException('Comment message must not exceed ' . IComment::MAX_MESSAGE_LENGTH . ' characters'); + } + $this->data['message'] = $message; return $this; } diff --git a/lib/public/comments/icomment.php b/lib/public/comments/icomment.php index e695b5193f2..a7f4b4c6171 100644 --- a/lib/public/comments/icomment.php +++ b/lib/public/comments/icomment.php @@ -29,6 +29,7 @@ namespace OCP\Comments; * @since 9.0.0 */ interface IComment { + const MAX_MESSAGE_LENGTH = 1000; /** * returns the ID of the comment @@ -119,8 +120,12 @@ interface IComment { /** * sets the message of the comment and returns itself * + * When the given message length exceeds MAX_MESSAGE_LENGTH an + * MessageTooLongException shall be thrown. + * * @param string $message * @return IComment + * @throws MessageTooLongException * @since 9.0.0 */ public function setMessage($message); diff --git a/lib/public/comments/messagetoolongexception.php b/lib/public/comments/messagetoolongexception.php new file mode 100644 index 00000000000..5b2809ae9ce --- /dev/null +++ b/lib/public/comments/messagetoolongexception.php @@ -0,0 +1,27 @@ +<?php +/** + * @author Arthur Schiwon <blizzz@owncloud.com> + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see <http://www.gnu.org/licenses/> + * + */ +namespace OCP\Comments; + +/** + * Exception for not found entity + * @since 9.0.0 + */ +class MessageTooLongException extends \Exception {} |