Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2018-07-24 22:58:31 +0300
committerStan Hu <stanhu@gmail.com>2018-07-24 23:00:49 +0300
commitbe495c6a80fadd6c741b82c7e9d585f3f1ab349b (patch)
treeb03a82ca958aba4b17f64feaa76eafcdc26b3c03 /spec
parentc06e2ac888fb5180cdf133df89d03b99eceafa0d (diff)
Fix slow Markdown rendering
The sanitize transformers were being duplicated each time the Markdown renderer was called, leading to expontential growth in rendering times. The problem was that although HTML::Pipeline::SanitizationFilter.WHITELIST is a frozen hash, the `:transformers` array can be modified. We need to do deep copy of this to avoid adding duplicates. Closes #49409
Diffstat (limited to 'spec')
-rw-r--r--spec/lib/banzai/filter/sanitization_filter_spec.rb12
1 files changed, 12 insertions, 0 deletions
diff --git a/spec/lib/banzai/filter/sanitization_filter_spec.rb b/spec/lib/banzai/filter/sanitization_filter_spec.rb
index d930c608b18..0b3c2390304 100644
--- a/spec/lib/banzai/filter/sanitization_filter_spec.rb
+++ b/spec/lib/banzai/filter/sanitization_filter_spec.rb
@@ -54,6 +54,18 @@ describe Banzai::Filter::SanitizationFilter do
expect(instance.whitelist[:transformers].size).to eq control_count
end
+ it 'customizes the whitelist only once for different instances' do
+ instance1 = described_class.new('Foo1')
+ instance2 = described_class.new('Foo2')
+ control_count = instance1.whitelist[:transformers].size
+
+ instance1.whitelist
+ instance2.whitelist
+
+ expect(instance1.whitelist[:transformers].size).to eq control_count
+ expect(instance2.whitelist[:transformers].size).to eq control_count
+ end
+
it 'sanitizes `class` attribute from all elements' do
act = %q{<pre class="code highlight white c"><code>&lt;span class="k"&gt;def&lt;/span&gt;</code></pre>}
exp = %q{<pre><code>&lt;span class="k"&gt;def&lt;/span&gt;</code></pre>}