From b83c2c9811ebf03dccc35d8f9c69012856e2f2de Mon Sep 17 00:00:00 2001 From: ccd0 Date: Fri, 24 Apr 2015 01:02:57 -0700 Subject: [PATCH] Fix whitespace being stripped from the comment before filtering. This makes it possible to filter whitespace spam. --- src/General/Get.coffee | 2 +- src/General/lib/post.class | 36 +++++++++++++++++++++--------------- src/Monitoring/Unread.coffee | 2 +- 3 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/General/Get.coffee b/src/General/Get.coffee index bfd705f9e..9dffdf722 100755 --- a/src/General/Get.coffee +++ b/src/General/Get.coffee @@ -3,7 +3,7 @@ Get = {OP} = thread excerpt = "/#{thread.board}/ - " + ( OP.info.subject?.trim() or - OP.info.comment.replace(/\n+/g, ' // ') or + OP.info.commentDisplay.replace(/\n+/g, ' // ') or OP.info.nameBlock) return "#{excerpt[...70]}..." if excerpt.length > 73 excerpt diff --git a/src/General/lib/post.class b/src/General/lib/post.class index f62e65377..2fdd4591e 100755 --- a/src/General/lib/post.class +++ b/src/General/lib/post.class @@ -106,22 +106,28 @@ class Post # 'Comment too long'... # EXIF data. (/p/) # Rolls. (/tg/) - # Marquees. (/pol/) + # Fortunes. (/s4s/) + bq = @nodes.comment.cloneNode true + for node in $$ '.abbr + br, .exif, b, .fortune', bq + $.rm node + if abbr = $ '.abbr', bq + $.rm abbr + @info.comment = @nodesToText bq + if abbr + @info.comment = @info.comment.replace /\n\n$/, '' + + # Hide spoilers. + # Remove: # Preceding and following new lines. # Trailing spaces. - bq = @nodes.comment.cloneNode true - for node in $$ '.abbr, .exif, b, marquee', bq - $.rm node - @info.comment = @nodesToText bq - - # Get the comment's text with spoilers hidden. - spoilers = $$ 's', bq - @info.commentSpoilered = if spoilers.length - for node in spoilers - $.replace node, $.tn '[spoiler]' - @nodesToText bq - else - @info.comment + commentDisplay = @info.comment + unless Conf['Remove Spoilers'] or Conf['Reveal Spoilers'] + spoilers = $$ 's', bq + if spoilers.length + for node in spoilers + $.replace node, $.tn '[spoiler]' + commentDisplay = @nodesToText bq + @info.commentDisplay = commentDisplay.trim().replace /\s+$/gm, '' nodesToText: (bq) -> text = "" @@ -129,7 +135,7 @@ class Post i = 0 while node = nodes.snapshotItem i++ text += node.data or '\n' - text.trim().replace /\s+$/gm, '' + text parseQuotes: -> @quotes = [] diff --git a/src/Monitoring/Unread.coffee b/src/Monitoring/Unread.coffee index 74e485977..2934fce49 100755 --- a/src/Monitoring/Unread.coffee +++ b/src/Monitoring/Unread.coffee @@ -128,7 +128,7 @@ Unread = openNotification: (post) -> return unless Header.areNotificationsEnabled notif = new Notification "#{post.info.nameBlock} replied to you", - body: post.info[if Conf['Remove Spoilers'] or Conf['Reveal Spoilers'] then 'comment' else 'commentSpoilered'] + body: post.info.commentDisplay icon: Favicon.logo notif.onclick = -> Header.scrollToIfNeeded post.nodes.root, true