Don't allow empty post content

Parsing the post content makes it non-empty (`<t></t>`), so we don't
parse it if it is empty. Also delete a created discussion if the first
post was invalid.

closes flarum/core#224
This commit is contained in:
Toby Zerner 2015-08-13 13:03:49 +09:30
parent 9a0190e13a
commit 58223b8a23
2 changed files with 11 additions and 4 deletions

View File

@ -6,6 +6,7 @@ use Illuminate\Contracts\Bus\Dispatcher;
use Flarum\Core\Discussions\Discussion; use Flarum\Core\Discussions\Discussion;
use Flarum\Core\Posts\Commands\PostReply; use Flarum\Core\Posts\Commands\PostReply;
use Flarum\Core\Support\DispatchesEvents; use Flarum\Core\Support\DispatchesEvents;
use Exception;
class StartDiscussionHandler class StartDiscussionHandler
{ {
@ -57,9 +58,15 @@ class StartDiscussionHandler
// Now that the discussion has been created, we can add the first post. // Now that the discussion has been created, we can add the first post.
// We will do this by running the PostReply command. // We will do this by running the PostReply command.
$post = $this->bus->dispatch( try {
new PostReply($discussion->id, $actor, $data) $post = $this->bus->dispatch(
); new PostReply($discussion->id, $actor, $data)
);
} catch (Exception $e) {
$discussion->delete();
throw $e;
}
// Before we dispatch events, refresh our discussion instance's // Before we dispatch events, refresh our discussion instance's
// attributes as posting the reply will have changed some of them (e.g. // attributes as posting the reply will have changed some of them (e.g.

View File

@ -142,7 +142,7 @@ class CommentPost extends Post
*/ */
public function setContentAttribute($value) public function setContentAttribute($value)
{ {
$this->attributes['content'] = static::$formatter->parse($value, $this); $this->attributes['content'] = $value ? static::$formatter->parse($value, $this) : null;
} }
/** /**