diff options
author | Go MAEDA <maeda@farend.jp> | 2025-01-02 02:44:39 +0000 |
---|---|---|
committer | Go MAEDA <maeda@farend.jp> | 2025-01-02 02:44:39 +0000 |
commit | 9e80ee95e1fb2867a9f61693d9afa6a6ba4e79c2 (patch) | |
tree | da89955afa46f05acb4a71fd848a7d0ef1ca6dc0 | |
parent | 254e8353be809223d2911b5bc02ecd98db954eb1 (diff) | |
download | redmine-9e80ee95e1fb2867a9f61693d9afa6a6ba4e79c2.tar.gz redmine-9e80ee95e1fb2867a9f61693d9afa6a6ba4e79c2.zip |
Abbreviate quoted text in descriptions in Activity view (#42043).
Patch by Go MAEDA (user:maeda).
git-svn-id: https://svn.redmine.org/redmine/trunk@23428 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r-- | app/helpers/application_helper.rb | 12 | ||||
-rw-r--r-- | test/helpers/application_helper_test.rb | 29 |
2 files changed, 39 insertions, 2 deletions
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index b50930676..3174261a9 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -414,8 +414,16 @@ module ApplicationHelper end def format_activity_description(text) - h(text.to_s.truncate(240).gsub(%r{[\r\n]*<(pre|code)>.*$}m, '...')). - gsub(/[\r\n]+/, "<br />").html_safe + h( + # Limit input to avoid regex performance issues + text.to_s.slice(0, 10240) + # Abbreviate consecutive quoted lines as '> ...', keeping the first line + .gsub(%r{(^>.*?(?:\r?\n))(?:>.*?(?:\r?\n)+)+}m, "\\1> ...\n") + # Remove all content following the first <pre> or <code> tag + .sub(%r{[\r\n]*<(pre|code)>.*$}m, '') + # Truncate the description to a specified length and append '...' + .truncate(240) + ).gsub(/[\r\n]+/, "<br>").html_safe end def format_version_name(version) diff --git a/test/helpers/application_helper_test.rb b/test/helpers/application_helper_test.rb index 9f2eb8405..31c87daea 100644 --- a/test/helpers/application_helper_test.rb +++ b/test/helpers/application_helper_test.rb @@ -2329,6 +2329,35 @@ class ApplicationHelperTest < Redmine::HelperTest end end + def test_format_activity_description_should_strip_quoted_text + text = <<~TEXT + John Smith wrote in #note-1: + > The quick brown fox + > jumps over the lazy dog. + + Brick quiz whangs jumpy veldt fox. + + > The five + + > boxing wizards + + > jump quickly. + + The quick onyx goblin jumps over the lazy dwarf. + TEXT + + expected = + 'John Smith wrote in #note-1:<br>' \ + '> The quick brown fox<br>' \ + '> ...<br>' \ + 'Brick quiz whangs jumpy veldt fox.<br>' \ + '> The five<br>' \ + '> ...<br>' \ + 'The quick onyx goblin jumps over the lazy dwarf.<br>' + + assert_equal expected, format_activity_description(text) + end + private def wiki_links_with_special_characters |