summaryrefslogtreecommitdiff
path: root/lib/banzai
diff options
context:
space:
mode:
authorBrett Walker <bwalker@gitlab.com>2019-01-10 17:28:44 -0600
committerBrett Walker <bwalker@gitlab.com>2019-01-10 17:28:44 -0600
commitcc036417278111efc7e8e686339ab0191a324364 (patch)
tree7ba6afcbc0494133928a5939c072825d57a861cb /lib/banzai
parent459d6f98126749cbd76cca20082c4ec6d4d57bb9 (diff)
downloadgitlab-ce-cc036417278111efc7e8e686339ab0191a324364.tar.gz
Updates based on review comments
Diffstat (limited to 'lib/banzai')
-rw-r--r--lib/banzai/filter/footnote_filter.rb14
-rw-r--r--lib/banzai/filter/sanitization_filter.rb4
2 files changed, 9 insertions, 9 deletions
diff --git a/lib/banzai/filter/footnote_filter.rb b/lib/banzai/filter/footnote_filter.rb
index a7120fbd46e..dc00ca73147 100644
--- a/lib/banzai/filter/footnote_filter.rb
+++ b/lib/banzai/filter/footnote_filter.rb
@@ -16,25 +16,25 @@ module Banzai
# can be used for a single render). So you get `id=fn1-4335` and `id=fn2-4335`.
#
class FootnoteFilter < HTML::Pipeline::Filter
- INTEGER_PATTERN = /\A\d+\Z/.freeze
+ INTEGER_PATTERN = /\A\d+\z/.freeze
def call
return doc unless first_footnote = doc.at_css('ol > li[id=fn1]')
# Sanitization stripped off the section wrapper - add it back in
first_footnote.parent.wrap('<section class="footnotes">')
+ rand_suffix = "-#{random_number}"
doc.css('sup > a[id]').each do |link_node|
ref_num = link_node[:id].delete_prefix('fnref')
footnote_node = doc.at_css("li[id=fn#{ref_num}]")
- backref_node = doc.at_css("li[id=fn#{ref_num}] a[href=\"#fnref#{ref_num}\"]")
+ backref_node = footnote_node.at_css("a[href=\"#fnref#{ref_num}\"]")
if ref_num =~ INTEGER_PATTERN && footnote_node && backref_node
- rand_ref_num = "#{ref_num}-#{random_number}"
- link_node[:href] = "#fn#{rand_ref_num}"
- link_node[:id] = "fnref#{rand_ref_num}"
- footnote_node[:id] = "fn#{rand_ref_num}"
- backref_node[:href] = "#fnref#{rand_ref_num}"
+ link_node[:href] += rand_suffix
+ link_node[:id] += rand_suffix
+ footnote_node[:id] += rand_suffix
+ backref_node[:href] += rand_suffix
# Sanitization stripped off class - add it back in
link_node.parent.append_class('footnote-ref')
diff --git a/lib/banzai/filter/sanitization_filter.rb b/lib/banzai/filter/sanitization_filter.rb
index d05518edcea..16accefa850 100644
--- a/lib/banzai/filter/sanitization_filter.rb
+++ b/lib/banzai/filter/sanitization_filter.rb
@@ -10,8 +10,8 @@ module Banzai
UNSAFE_PROTOCOLS = %w(data javascript vbscript).freeze
TABLE_ALIGNMENT_PATTERN = /text-align: (?<alignment>center|left|right)/.freeze
- FOOTNOTE_LINK_REFERENCE_PATTERN = /\Afnref\d\z/.freeze
- FOOTNOTE_LI_REFERENCE_PATTERN = /\Afn\d\z/.freeze
+ FOOTNOTE_LINK_REFERENCE_PATTERN = /\Afnref\d+\z/.freeze
+ FOOTNOTE_LI_REFERENCE_PATTERN = /\Afn\d+\z/.freeze
def whitelist
strong_memoize(:whitelist) do