Skip to content

Commit c547b8b

Browse files
author
joeltaylor
committed
Return error if edited comment is empty
1 parent 4ead1e1 commit c547b8b

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

server/controllers/news.js

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,20 +119,30 @@ router.
119119
}
120120
}).
121121

122-
put('/:slug([a-zA-Z0-9_.-]+)/comment/:id([a-zA-Z0-9_.-]+)', cookieParser, authenticator.authorize, parseForm, csrfProtection, function(req, res) {
122+
put('/:slug([a-zA-Z0-9_.-]+)/comment/:id([a-zA-Z0-9_.-]+)', cookieParser, authenticator.authorize, parseForm, expressValidator(), csrfProtection, function(req, res) {
123+
// Validations
124+
req.sanitize('body').trim();
125+
req.check('body').notEmpty();
126+
127+
var errors = req.validationErrors();
128+
123129
var args = {
124130
updatedComment : req.body.body,
125131
commentId : req.params.id,
126132
userId : req.session.passport.user.uid
127133
}
128134

129-
Articles.editComment(args, function(err, doc){
130-
if(doc){
131-
res.json({comment: doc})
132-
}else{
133-
res.send(404)
134-
}
135-
});
135+
if(errors){
136+
res.send(400);
137+
}else{
138+
Articles.editComment(args, function(err, doc){
139+
if(doc){
140+
res.json({comment: doc})
141+
}else{
142+
res.send(404)
143+
}
144+
});
145+
}
136146
}).
137147

138148
delete('/:slug([a-zA-Z0-9_.-]+)/comment/:id([a-zA-Z0-9_.-]+)', cookieParser, authenticator.authorize, csrfProtection, function(req, res) {

0 commit comments

Comments
 (0)