From d88b21fb5e7e2073c7ca49c117ebdd6fc8b6b3fe Mon Sep 17 00:00:00 2001 From: Mojca Lorber Date: Thu, 1 Jun 2017 15:09:01 +0200 Subject: [PATCH 1/3] truncate all titles in activities --- app/helpers/activity_helper.rb | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/app/helpers/activity_helper.rb b/app/helpers/activity_helper.rb index bf0841b81..f65882547 100644 --- a/app/helpers/activity_helper.rb +++ b/app/helpers/activity_helper.rb @@ -1,13 +1,16 @@ module ActivityHelper def activity_truncate(message, len = Constants::NAME_TRUNCATION_LENGTH) - activity_title = message.match(/(.*?)<\/strong>/)[1] - if activity_title.length > Constants::NAME_TRUNCATION_LENGTH - title = "" - else - title = truncate(activity_title, length: len) + activity_titles = message.scan(/(.*?)<\/strong>/) + activity_titles.each do |activity_title| + activity_title = activity_title[0] + if activity_title.length > Constants::NAME_TRUNCATION_LENGTH + title = "" + else + title = truncate(activity_title, length: len) + end + message = message.gsub(/#{activity_title}/, title ) end - message = message.gsub(/#{activity_title}/, title ) sanitize_input(message) if message end From 7c2b657b0e628585eca0f0e2d9cc1b029a020b80 Mon Sep 17 00:00:00 2001 From: Mojca Lorber Date: Thu, 1 Jun 2017 15:10:26 +0200 Subject: [PATCH 2/3] fix bug with special characters when truncating activities titles --- app/helpers/activity_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/helpers/activity_helper.rb b/app/helpers/activity_helper.rb index f65882547..965e828a2 100644 --- a/app/helpers/activity_helper.rb +++ b/app/helpers/activity_helper.rb @@ -9,7 +9,7 @@ module ActivityHelper else title = truncate(activity_title, length: len) end - message = message.gsub(/#{activity_title}/, title ) + message = message.gsub(/#{Regexp.escape(activity_title)}/, title ) end sanitize_input(message) if message end From 27d3a5097b106bb710f6f50c3055c5190e70034e Mon Sep 17 00:00:00 2001 From: Mojca Lorber Date: Mon, 5 Jun 2017 16:07:21 +0200 Subject: [PATCH 3/3] fix hound --- app/helpers/activity_helper.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/app/helpers/activity_helper.rb b/app/helpers/activity_helper.rb index 965e828a2..83cf57023 100644 --- a/app/helpers/activity_helper.rb +++ b/app/helpers/activity_helper.rb @@ -4,12 +4,16 @@ module ActivityHelper activity_titles.each do |activity_title| activity_title = activity_title[0] if activity_title.length > Constants::NAME_TRUNCATION_LENGTH - title = "" + title = "" else title = truncate(activity_title, length: len) end - message = message.gsub(/#{Regexp.escape(activity_title)}/, title ) + message = message.gsub(/#{Regexp.escape(activity_title)}/, title) end sanitize_input(message) if message end