aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-02-20 10:41:11 +0100
committerChocobozzz <me@florianbigard.com>2018-02-20 10:41:11 +0100
commit5de8a55abce53108bc1024f1194457c6528bd11e (patch)
tree24d55c349807581a86872490753c2e1bddff932d
parent2f315e2f915514eaddee30394b0d99790bcda06b (diff)
downloadPeerTube-5de8a55abce53108bc1024f1194457c6528bd11e.tar.gz
PeerTube-5de8a55abce53108bc1024f1194457c6528bd11e.tar.zst
PeerTube-5de8a55abce53108bc1024f1194457c6528bd11e.zip
Handle line feeds in comments
-rw-r--r--client/src/app/shared/misc/utils.ts9
-rw-r--r--client/src/app/videos/+video-watch/comment/video-comment.component.ts2
-rw-r--r--client/src/app/videos/+video-watch/comment/video-comment.service.ts7
-rw-r--r--server/middlewares/validators/video-comments.ts4
4 files changed, 16 insertions, 6 deletions
diff --git a/client/src/app/shared/misc/utils.ts b/client/src/app/shared/misc/utils.ts
index e2e4c5b36..64bc69b0d 100644
--- a/client/src/app/shared/misc/utils.ts
+++ b/client/src/app/shared/misc/utils.ts
@@ -88,6 +88,12 @@ function objectToFormData (obj: any, form?: FormData, namespace?: string) {
88 return fd 88 return fd
89} 89}
90 90
91function lineFeedToHtml (obj: object, keyToNormalize: string) {
92 return immutableAssign(obj, {
93 [keyToNormalize]: obj[keyToNormalize].replace(/\r?\n|\r/g, '<br />')
94 })
95}
96
91export { 97export {
92 viewportHeight, 98 viewportHeight,
93 getParameterByName, 99 getParameterByName,
@@ -97,5 +103,6 @@ export {
97 isInSmallView, 103 isInSmallView,
98 isInMobileView, 104 isInMobileView,
99 immutableAssign, 105 immutableAssign,
100 objectToFormData 106 objectToFormData,
107 lineFeedToHtml
101} 108}
diff --git a/client/src/app/videos/+video-watch/comment/video-comment.component.ts b/client/src/app/videos/+video-watch/comment/video-comment.component.ts
index 7c664ca60..9176de80f 100644
--- a/client/src/app/videos/+video-watch/comment/video-comment.component.ts
+++ b/client/src/app/videos/+video-watch/comment/video-comment.component.ts
@@ -90,7 +90,7 @@ export class VideoCommentComponent implements OnInit, OnChanges {
90 90
91 private init () { 91 private init () {
92 this.sanitizedCommentHTML = sanitizeHtml(this.comment.text, { 92 this.sanitizedCommentHTML = sanitizeHtml(this.comment.text, {
93 allowedTags: [ 'p', 'span' ] 93 allowedTags: [ 'p', 'span', 'br' ]
94 }) 94 })
95 95
96 this.newParentComments = this.parentComments.concat([ this.comment ]) 96 this.newParentComments = this.parentComments.concat([ this.comment ])
diff --git a/client/src/app/videos/+video-watch/comment/video-comment.service.ts b/client/src/app/videos/+video-watch/comment/video-comment.service.ts
index c42f55496..14d32b1aa 100644
--- a/client/src/app/videos/+video-watch/comment/video-comment.service.ts
+++ b/client/src/app/videos/+video-watch/comment/video-comment.service.ts
@@ -2,6 +2,7 @@ import { HttpClient, HttpParams } from '@angular/common/http'
2import { Injectable } from '@angular/core' 2import { Injectable } from '@angular/core'
3import 'rxjs/add/operator/catch' 3import 'rxjs/add/operator/catch'
4import 'rxjs/add/operator/map' 4import 'rxjs/add/operator/map'
5import { immutableAssign, lineFeedToHtml } from '@app/shared/misc/utils'
5import { Observable } from 'rxjs/Observable' 6import { Observable } from 'rxjs/Observable'
6import { ResultList } from '../../../../../../shared/models' 7import { ResultList } from '../../../../../../shared/models'
7import { 8import {
@@ -26,16 +27,18 @@ export class VideoCommentService {
26 27
27 addCommentThread (videoId: number | string, comment: VideoCommentCreate) { 28 addCommentThread (videoId: number | string, comment: VideoCommentCreate) {
28 const url = VideoCommentService.BASE_VIDEO_URL + videoId + '/comment-threads' 29 const url = VideoCommentService.BASE_VIDEO_URL + videoId + '/comment-threads'
30 const normalizedComment = lineFeedToHtml(comment, 'text')
29 31
30 return this.authHttp.post(url, comment) 32 return this.authHttp.post(url, normalizedComment)
31 .map(data => this.extractVideoComment(data['comment'])) 33 .map(data => this.extractVideoComment(data['comment']))
32 .catch(this.restExtractor.handleError) 34 .catch(this.restExtractor.handleError)
33 } 35 }
34 36
35 addCommentReply (videoId: number | string, inReplyToCommentId: number, comment: VideoCommentCreate) { 37 addCommentReply (videoId: number | string, inReplyToCommentId: number, comment: VideoCommentCreate) {
36 const url = VideoCommentService.BASE_VIDEO_URL + videoId + '/comments/' + inReplyToCommentId 38 const url = VideoCommentService.BASE_VIDEO_URL + videoId + '/comments/' + inReplyToCommentId
39 const normalizedComment = lineFeedToHtml(comment, 'text')
37 40
38 return this.authHttp.post(url, comment) 41 return this.authHttp.post(url, normalizedComment)
39 .map(data => this.extractVideoComment(data['comment'])) 42 .map(data => this.extractVideoComment(data['comment']))
40 .catch(this.restExtractor.handleError) 43 .catch(this.restExtractor.handleError)
41 } 44 }
diff --git a/server/middlewares/validators/video-comments.ts b/server/middlewares/validators/video-comments.ts
index 63804da30..227bc1fca 100644
--- a/server/middlewares/validators/video-comments.ts
+++ b/server/middlewares/validators/video-comments.ts
@@ -43,7 +43,7 @@ const addVideoCommentThreadValidator = [
43 body('text').custom(isValidVideoCommentText).not().isEmpty().withMessage('Should have a valid comment text'), 43 body('text').custom(isValidVideoCommentText).not().isEmpty().withMessage('Should have a valid comment text'),
44 44
45 async (req: express.Request, res: express.Response, next: express.NextFunction) => { 45 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
46 logger.debug('Checking addVideoCommentThread parameters.', { parameters: req.params }) 46 logger.debug('Checking addVideoCommentThread parameters.', { parameters: req.params, body: req.body })
47 47
48 if (areValidationErrors(req, res)) return 48 if (areValidationErrors(req, res)) return
49 if (!await isVideoExist(req.params.videoId, res)) return 49 if (!await isVideoExist(req.params.videoId, res)) return
@@ -59,7 +59,7 @@ const addVideoCommentReplyValidator = [
59 body('text').custom(isValidVideoCommentText).not().isEmpty().withMessage('Should have a valid comment text'), 59 body('text').custom(isValidVideoCommentText).not().isEmpty().withMessage('Should have a valid comment text'),
60 60
61 async (req: express.Request, res: express.Response, next: express.NextFunction) => { 61 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
62 logger.debug('Checking addVideoCommentReply parameters.', { parameters: req.params }) 62 logger.debug('Checking addVideoCommentReply parameters.', { parameters: req.params, body: req.body })
63 63
64 if (areValidationErrors(req, res)) return 64 if (areValidationErrors(req, res)) return
65 if (!await isVideoExist(req.params.videoId, res)) return 65 if (!await isVideoExist(req.params.videoId, res)) return