Feature #42043 » 0002-Abbreviate-quoted-text-in-descriptions-in-Activity-v.patch
| app/helpers/application_helper.rb | ||
|---|---|---|
| 414 | 414 |
end |
| 415 | 415 | |
| 416 | 416 |
def format_activity_description(text) |
| 417 |
h(text.to_s.truncate(240).gsub(%r{[\r\n]*<(pre|code)>.*$}m, '...')).
|
|
| 418 |
gsub(/[\r\n]+/, "<br />").html_safe |
|
| 417 |
h( |
|
| 418 |
# Limit input to avoid regex performance issues |
|
| 419 |
text.to_s.slice(0, 10240) |
|
| 420 |
# Abbreviate consecutive quoted lines as '> ...' |
|
| 421 |
.gsub(%r{(?:^>.*?(?:\r?\n)+)+}m, "> ...\n")
|
|
| 422 |
# Remove all content following the first <pre> or <code> tag |
|
| 423 |
.sub(%r{[\r\n]*<(pre|code)>.*$}m, '')
|
|
| 424 |
# Truncate the description to a specified length and append '...' |
|
| 425 |
.truncate(240) |
|
| 426 |
).gsub(/[\r\n]+/, "<br>").html_safe |
|
| 419 | 427 |
end |
| 420 | 428 | |
| 421 | 429 |
def format_version_name(version) |
| test/helpers/application_helper_test.rb | ||
|---|---|---|
| 2329 | 2329 |
end |
| 2330 | 2330 |
end |
| 2331 | 2331 | |
| 2332 |
def test_format_activity_description_should_strip_quoted_text |
|
| 2333 |
text = <<~TEXT |
|
| 2334 |
John Smith wrote in #note-1: |
|
| 2335 |
> The quick brown fox |
|
| 2336 |
> jumps over the lazy dog. |
|
| 2337 | ||
| 2338 |
Brick quiz whangs jumpy veldt fox. |
|
| 2339 | ||
| 2340 |
> The five |
|
| 2341 | ||
| 2342 |
> boxing wizards |
|
| 2343 | ||
| 2344 |
> jump quickly. |
|
| 2345 | ||
| 2346 |
The quick onyx goblin jumps over the lazy dwarf. |
|
| 2347 |
TEXT |
|
| 2348 | ||
| 2349 |
expected = |
|
| 2350 |
'John Smith wrote in #note-1:<br>' \ |
|
| 2351 |
'> ...<br>' \ |
|
| 2352 |
'Brick quiz whangs jumpy veldt fox.<br>' \ |
|
| 2353 |
'> ...<br>' \ |
|
| 2354 |
'The quick onyx goblin jumps over the lazy dwarf.<br>' |
|
| 2355 | ||
| 2356 |
assert_equal expected, format_activity_description(text) |
|
| 2357 |
end |
|
| 2358 | ||
| 2332 | 2359 |
private |
| 2333 | 2360 | |
| 2334 | 2361 |
def wiki_links_with_special_characters |