Escape HTML in chat & comments (#1342)

* Fix comment regex & live chat

* fix regex
This commit is contained in:
ChunkyProgrammer 2021-07-21 10:37:55 -04:00 committed by GitHub
parent 170c60276b
commit 6522521b88
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 7 deletions

View File

@ -250,7 +250,7 @@ export default Vue.extend({
if (this.hideCommentLikes) { if (this.hideCommentLikes) {
comment.likes = null comment.likes = null
} }
comment.text = autolinker.link(comment.text) comment.text = autolinker.link(comment.text.replace(/(<([^>]+)>)/ig, ''))
return comment return comment
}) })
@ -282,7 +282,7 @@ export default Vue.extend({
} else { } else {
comment.likes = comment.likeCount comment.likes = comment.likeCount
} }
comment.text = autolinker.link(comment.content) comment.text = autolinker.link(comment.content.replace(/(<([^>]+)>)/ig, ''))
comment.dataType = 'invidious' comment.dataType = 'invidious'
if (typeof (comment.replies) !== 'undefined' && typeof (comment.replies.replyCount) !== 'undefined') { if (typeof (comment.replies) !== 'undefined' && typeof (comment.replies.replyCount) !== 'undefined') {
@ -348,7 +348,7 @@ export default Vue.extend({
} else { } else {
comment.likes = comment.likeCount comment.likes = comment.likeCount
} }
comment.text = autolinker.link(comment.content) comment.text = autolinker.link(comment.content.replace(/(<([^>]+)>)/ig, ''))
comment.time = comment.publishedText comment.time = comment.publishedText
comment.dataType = 'invidious' comment.dataType = 'invidious'
comment.numReplies = 0 comment.numReplies = 0

View File

@ -157,15 +157,15 @@ export default Vue.extend({
if (typeof (text.navigationEndpoint) !== 'undefined') { if (typeof (text.navigationEndpoint) !== 'undefined') {
if (typeof (text.navigationEndpoint.watchEndpoint) !== 'undefined') { if (typeof (text.navigationEndpoint.watchEndpoint) !== 'undefined') {
const htmlRef = `<a href="https://www.youtube.com/watch?v=${text.navigationEndpoint.watchEndpoint.videoId}">${text.text}</a>` const htmlRef = `<a href="https://www.youtube.com/watch?v=${text.navigationEndpoint.watchEndpoint.videoId}">${text.text}</a>`
comment.messageHtml = comment.messageHtml + htmlRef comment.messageHtml = comment.messageHtml.replace(/(<([^>]+)>)/ig, '') + htmlRef
} else { } else {
comment.messageHtml = comment.messageHtml + text.text comment.messageHtml = (comment.messageHtml + text.text).replace(/(<([^>]+)>)/ig, '')
} }
} else if (typeof (text.alt) !== 'undefined') { } else if (typeof (text.alt) !== 'undefined') {
const htmlImg = `<img src="${text.url}" alt="${text.alt}" height="24" width="24" />` const htmlImg = `<img src="${text.url}" alt="${text.alt}" height="24" width="24" />`
comment.messageHtml = comment.messageHtml + htmlImg comment.messageHtml = comment.messageHtml.replace(/(<([^>]+)>)/ig, '') + htmlImg
} else { } else {
comment.messageHtml = comment.messageHtml + text.text comment.messageHtml = (comment.messageHtml + text.text).replace(/(<([^>]+)>)/ig, '')
} }
}) })