From 66e9aaa45fd2c5c471bc3dcfc72ec0f34fb2e7da Mon Sep 17 00:00:00 2001 From: Brett Walker <bwalker@gitlab.com> Date: Wed, 28 Sep 2022 15:40:41 -0500 Subject: [PATCH] Update to latest commonmarker/cmark-gfm to replace our pathological_markdown_filter --- Gemfile | 2 +- Gemfile.checksum | 2 +- Gemfile.lock | 4 +-- .../filter/pathological_markdown_filter.rb | 27 ------------------- .../pipeline/plain_markdown_pipeline.rb | 1 - .../pathological_markdown_filter_spec.rb | 27 ------------------- .../lib/banzai/pipeline/full_pipeline_spec.rb | 16 +++++------ 7 files changed, 11 insertions(+), 68 deletions(-) delete mode 100644 lib/banzai/filter/pathological_markdown_filter.rb delete mode 100644 spec/lib/banzai/filter/pathological_markdown_filter_spec.rb diff --git a/Gemfile b/Gemfile index 947fc9914a2a..32416fe0aef7 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 51893fa0557d..abfe74c5d17b 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 b589d5edbff8..53f19eb497b9 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 0f94150c7a1f..000000000000 --- 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 fb6f6e9077d8..1da0f72996be 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 e0a07d1ea772..000000000000 --- 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 c07f99dc9fc8..1a0f5a53a23e 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 -- GitLab