diff --git a/CHANGELOG b/CHANGELOG index d00d3fab9a..43411be3bf 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -15,6 +15,7 @@ v 8.8.3 - Fix incorrect links on pipeline page when merge request created from fork. !4376 - Use downcased path to container repository as this is expected path by Docker. !4420 - Fix wiki project clone address error (chujinjin). !4429 + - Fix serious performance bug with rendering Markdown with InlineDiffFilter. !4392 - In search results, only show notes on confidential issues that the user has access to v 8.8.2 diff --git a/lib/banzai/filter/inline_diff_filter.rb b/lib/banzai/filter/inline_diff_filter.rb index 9e75edd4d4..beb21b19ab 100644 --- a/lib/banzai/filter/inline_diff_filter.rb +++ b/lib/banzai/filter/inline_diff_filter.rb @@ -8,15 +8,19 @@ module Banzai next if has_ancestor?(node, IGNORED_ANCESTOR_TAGS) content = node.to_html - content = content.gsub(/(?:\[\-(.*?)\-\]|\{\-(.*?)\-\})/, '\1\2') - content = content.gsub(/(?:\[\+(.*?)\+\]|\{\+(.*?)\+\})/, '\1\2') + html_content = inline_diff_filter(content) - next if html == content + next if content == html_content - node.replace(content) + node.replace(html_content) end doc end + + def inline_diff_filter(text) + html_content = text.gsub(/(?:\[\-(.*?)\-\]|\{\-(.*?)\-\})/, '\1\2') + html_content.gsub(/(?:\[\+(.*?)\+\]|\{\+(.*?)\+\})/, '\1\2') + end end end end