OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
keep special chars on activity page
ulferts2c5da8e1eff1
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rbindex 2e92e31e9c2..663ebde422c 100644--- a/app/helpers/application_helper.rb+++ b/app/helpers/application_helper.rb@@ -110,7 +110,8 @@ module ApplicationHelperenddef format_activity_description(text)- html_escape_once(truncate(text.to_s, length: 120).gsub(%r{[\r\n]*<(pre|code)>.*$}m, '...'))+ truncate_lines(strip_tags(format_text(text.to_s)).html_safe, length: 120)+ .strip.gsub(/[\r\n]+/, '<br />').html_safeenddiff --git a/lib/open_project/text_formatting/truncation.rb b/lib/open_project/text_formatting/truncation.rbindex 0de539da74c..ca26236327c 100644--- a/lib/open_project/text_formatting/truncation.rb+++ b/lib/open_project/text_formatting/truncation.rb@@ -37,10 +37,9 @@ module OpenProjecttruncate(string.to_s, *args).gsub(%r{[\r\n]+}m, ' ').html_safeend- # Truncates at line break after 250 characters or options[:length]- def truncate_lines(string, options = {})- length = options[:length] || 250- if string.to_s =~ /\A(.{#{length}}.*?)$/m+ # Truncates at line break after 250 characters+ def truncate_lines(string, length: 250)+ if string.to_s =~ /\A(.{#{length}}).*?$/m"#{$1}..."elsestringdiff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rbindex 46dd871dd57..6f698ed93ef 100644--- a/spec/helpers/application_helper_spec.rb+++ b/spec/helpers/application_helper_spec.rb@@ -35,19 +35,22 @@ describe ApplicationHelper, type: :helper dodescribe 'format_activity_description' doit 'truncates given text' dotext = 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lore'- expect(format_activity_description(text).size).to eq(120)+ expect(format_activity_description(text).size).to eq(123)endit 'replaces escaped line breaks with html line breaks and should be html_safe' do- text = "Lorem ipsum dolor sit \namet, consetetur sadipscing elitr, sed diam nonumy eirmod\r tempor invidunt"- text_html = 'Lorem ipsum dolor sit <br />amet, consetetur sadipscing elitr, sed diam nonumy eirmod<br /> tempor invidunt'- expect(format_activity_description(text)).to be_html_eql(text_html)- expect(format_activity_description(text).html_safe?).to be_truthy+ text = "Lorem ipsum dolor sit \namet, consetetur sadipscing elitr, sed diam nonumy eirmod\n tempor invidunt"+ text_html = 'Lorem ipsum dolor sit <br /> amet, consetetur sadipscing elitr, sed diam nonumy eirmod <br /> tempor invidunt'+ expect(format_activity_description(text))+ .to be_html_eql(text_html)+ expect(format_activity_description(text))+ .to be_html_safeendit 'escapes potentially harmful code' dotext = "Lorem ipsum dolor <script>alert('pwnd');</script> tempor invidunt"- expect(format_activity_description(text).include?('<script>alert('pwnd');</script>')).to be_truthy+ expect(format_activity_description(text))+ .to include('<script>alert(\'pwnd\');</script>')endend