aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-03-21 15:00:58 +0100
committerChocobozzz <me@florianbigard.com>2018-03-21 15:00:58 +0100
commitbffbebbe6b33ce306e7ec1b6051f0e51521c0440 (patch)
tree70cc5b1eaba4520619b690b4755d19528689360a /server/models
parenta3cffab42d78560a7db8ad1df14680be5b55277f (diff)
downloadPeerTube-bffbebbe6b33ce306e7ec1b6051f0e51521c0440.tar.gz
PeerTube-bffbebbe6b33ce306e7ec1b6051f0e51521c0440.tar.zst
PeerTube-bffbebbe6b33ce306e7ec1b6051f0e51521c0440.zip
Fix issues with truncated description and utf characters
Diffstat (limited to 'server/models')
-rw-r--r--server/models/video/video.ts11
1 files changed, 10 insertions, 1 deletions
diff --git a/server/models/video/video.ts b/server/models/video/video.ts
index 4e175c410..f43b73e49 100644
--- a/server/models/video/video.ts
+++ b/server/models/video/video.ts
@@ -1166,10 +1166,19 @@ export class VideoModel extends Model<VideoModel> {
1166 getTruncatedDescription () { 1166 getTruncatedDescription () {
1167 if (!this.description) return null 1167 if (!this.description) return null
1168 1168
1169 const maxLength = CONSTRAINTS_FIELDS.VIDEOS.TRUNCATED_DESCRIPTION.max
1170
1169 const options = { 1171 const options = {
1170 length: CONSTRAINTS_FIELDS.VIDEOS.TRUNCATED_DESCRIPTION.max 1172 length: maxLength
1171 } 1173 }
1174 const truncatedDescription = truncate(this.description, options)
1175
1176 // The truncated string is okay, we can return it
1177 if (truncatedDescription.length <= maxLength) return truncatedDescription
1172 1178
1179 // Lodash takes into account all UTF characters, whereas String.prototype.length does not: some characters have a length of 2
1180 // We always use the .length so we need to truncate more if needed
1181 options.length -= maxLength - truncatedDescription.length
1173 return truncate(this.description, options) 1182 return truncate(this.description, options)
1174 } 1183 }
1175 1184