Project

General

Profile

Feature #42043 » 0002-Abbreviate-quoted-text-in-descriptions-in-Activity-v.patch

Go MAEDA, 2024-12-26 02:52

View differences:

app/helpers/application_helper.rb
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 '> ...'
.gsub(%r{(?:^>.*?(?:\r?\n)+)+}m, "> ...\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)
test/helpers/application_helper_test.rb
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>' \
'&gt; ...<br>' \
'Brick quiz whangs jumpy veldt fox.<br>' \
'&gt; ...<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
(3-3/5)