diff --git a/Gemfile b/Gemfile index 947fc9914a2af3333cab22a80f33833ef3280e2c..32416fe0aef717041df7803f398e9608e6482b6b 100644 --- a/Gemfile +++ b/Gemfile @@ -165,7 +165,7 @@ gem 'html-pipeline', '~> 2.13.2' gem 'deckar01-task_list', '2.3.1' gem 'gitlab-markup', '~> 1.8.0' gem 'github-markup', '~> 1.7.0', require: 'github/markup' -gem 'commonmarker', '~> 0.23.4' +gem 'commonmarker', '~> 0.23.6' gem 'kramdown', '~> 2.3.1' gem 'RedCloth', '~> 4.3.2' gem 'rdoc', '~> 6.3.2' diff --git a/Gemfile.checksum b/Gemfile.checksum index 51893fa0557d9821934930fc194d450530fdeb5e..abfe74c5d17b531030bc481d8b5cd8924a668c13 100644 --- a/Gemfile.checksum +++ b/Gemfile.checksum @@ -79,7 +79,7 @@ {"name":"claide-plugins","version":"0.9.2","platform":"ruby","checksum":"c7ea78bc067ab23bce8515497cdcdcb8f01c86dadfbe13c44644e382922c1c2e"}, {"name":"coderay","version":"1.1.3","platform":"ruby","checksum":"dc530018a4684512f8f38143cd2a096c9f02a1fc2459edcfe534787a7fc77d4b"}, {"name":"colored2","version":"3.1.2","platform":"ruby","checksum":"b13c2bd7eeae2cf7356a62501d398e72fde78780bd26aec6a979578293c28b4a"}, -{"name":"commonmarker","version":"0.23.4","platform":"ruby","checksum":"95d9cb050576376374a66d71a4feab3562e0955aab9d80a3e8606a5cf5e9c7ce"}, +{"name":"commonmarker","version":"0.23.6","platform":"ruby","checksum":"c8aeaaaff4ba497bf180f762db63a0069794fafb6eff221224c9c8199d337b38"}, {"name":"concurrent-ruby","version":"1.1.10","platform":"ruby","checksum":"244cb1ca0d91ec2c15ca2209507c39fb163336994428e16fbd3f465c87bd8e68"}, {"name":"connection_pool","version":"2.2.5","platform":"ruby","checksum":"13a8fc3921ce4df8e04fb65f1037251decb08d74757b41163688bd1c1feccd39"}, {"name":"contracts","version":"0.11.0","platform":"ruby","checksum":"df6e438efa89c31dd3095851c3f7a25dfdae36b35ff1d4547f1d92941b3c7286"}, diff --git a/Gemfile.lock b/Gemfile.lock index b589d5edbff8d20128afe11ffc65a2b7a38724d1..53f19eb497b9415cba5ff673a44a0b0a9088b9dd 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -282,7 +282,7 @@ GEM open4 (~> 1.3) coderay (1.1.3) colored2 (3.1.2) - commonmarker (0.23.4) + commonmarker (0.23.6) concurrent-ruby (1.1.10) connection_pool (2.2.5) contracts (0.11.0) @@ -1557,7 +1557,7 @@ DEPENDENCIES capybara-screenshot (~> 1.0.22) carrierwave (~> 1.3) charlock_holmes (~> 0.7.7) - commonmarker (~> 0.23.4) + commonmarker (~> 0.23.6) concurrent-ruby (~> 1.1) connection_pool (~> 2.0) countries (~> 3.0) diff --git a/lib/banzai/filter/pathological_markdown_filter.rb b/lib/banzai/filter/pathological_markdown_filter.rb deleted file mode 100644 index 0f94150c7a1fdea31780b9e56ee9d2cac70d6445..0000000000000000000000000000000000000000 --- a/lib/banzai/filter/pathological_markdown_filter.rb +++ /dev/null @@ -1,27 +0,0 @@ -# frozen_string_literal: true - -module Banzai - module Filter - class PathologicalMarkdownFilter < HTML::Pipeline::TextFilter - # It's not necessary for this to be precise - we just need to detect - # when there are a non-trivial number of unclosed image links. - # So we don't really care about code blocks, etc. - # See https://gitlab.com/gitlab-org/gitlab/-/issues/370428 - REGEX = /!\[(?:[^\]])+?!\[/.freeze - DETECTION_MAX = 10 - - def call - count = 0 - - @text.scan(REGEX) do |_match| - count += 1 - break if count > DETECTION_MAX - end - - return @text if count <= DETECTION_MAX - - "_Unable to render markdown - too many unclosed markdown image links detected._" - end - end - end -end diff --git a/lib/banzai/pipeline/plain_markdown_pipeline.rb b/lib/banzai/pipeline/plain_markdown_pipeline.rb index fb6f6e9077d86cc40b5bd62f55397261242fdc63..1da0f72996bedaecad1d85260e762978a1925977 100644 --- a/lib/banzai/pipeline/plain_markdown_pipeline.rb +++ b/lib/banzai/pipeline/plain_markdown_pipeline.rb @@ -5,7 +5,6 @@ module Pipeline class PlainMarkdownPipeline < BasePipeline def self.filters FilterArray[ - Filter::PathologicalMarkdownFilter, Filter::MarkdownPreEscapeFilter, Filter::MarkdownFilter, Filter::MarkdownPostEscapeFilter diff --git a/spec/lib/banzai/filter/pathological_markdown_filter_spec.rb b/spec/lib/banzai/filter/pathological_markdown_filter_spec.rb deleted file mode 100644 index e0a07d1ea7724d2bbfa25390aa64ee42669308f7..0000000000000000000000000000000000000000 --- a/spec/lib/banzai/filter/pathological_markdown_filter_spec.rb +++ /dev/null @@ -1,27 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe Banzai::Filter::PathologicalMarkdownFilter do - include FilterSpecHelper - - let_it_be(:short_text) { '![a' * 5 } - let_it_be(:long_text) { ([short_text] * 10).join(' ') } - let_it_be(:with_images_text) { " #{'and\n' * 200} " } - - it 'detects a significat number of unclosed image links' do - msg = <<~TEXT - _Unable to render markdown - too many unclosed markdown image links detected._ - TEXT - - expect(filter(long_text)).to eq(msg.strip) - end - - it 'does nothing when there are only a few unclosed image links' do - expect(filter(short_text)).to eq(short_text) - end - - it 'does nothing when there are only a few unclosed image links and images' do - expect(filter(with_images_text)).to eq(with_images_text) - end -end diff --git a/spec/lib/banzai/pipeline/full_pipeline_spec.rb b/spec/lib/banzai/pipeline/full_pipeline_spec.rb index c07f99dc9fc8676ac8b07a8038d1a4b6b43e16f4..1a0f5a53a23e6c4bea1b3ce54e0fa0537797522f 100644 --- a/spec/lib/banzai/pipeline/full_pipeline_spec.rb +++ b/spec/lib/banzai/pipeline/full_pipeline_spec.rb @@ -168,15 +168,13 @@ end end - describe 'unclosed image links' do - it 'detects a significat number of unclosed image links' do - markdown = '![a ' * 30 - msg = <<~TEXT - Unable to render markdown - too many unclosed markdown image links detected. - TEXT - output = described_class.to_html(markdown, project: nil) - - expect(output).to include(msg.strip) + describe 'cmark-gfm and autlolinks' do + it 'does not hang with significant number of unclosed image links' do + markdown = '![a ' * 300000 + + expect do + Timeout.timeout(2.seconds) { described_class.to_html(markdown, project: nil) } + end.not_to raise_error end end end