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
diff options
context:
space:
mode:
authorRobert Speicher <rspeicher@gmail.com>2019-02-14 00:37:12 +0300
committerGitLab Release Tools Bot <robert+release-tools@gitlab.com>2019-02-14 19:10:22 +0300
commit72defb15ba8392af22040f2b918643f6d108305d (patch)
tree132cf622db98f5e5adaa140e3a0a80c6214ce28a /lib/banzai
parent33799a15368e8fab888a2479ccf5de96b8c91490 (diff)
Merge branch '57634-issue-when-viewing-a-document-with-footnotes-actionview-template-error-undefined-method-at_css-for-nil-nilclass' into 'master'
Issue when viewing a document with footnotes Closes #57634 See merge request gitlab-org/gitlab-ce!25199 (cherry picked from commit 69c19b392e4636093050f576d3056a10371b01b2) f8241f25 Properly handle multiple refs to same footnote
Diffstat (limited to 'lib/banzai')
-rw-r--r--lib/banzai/filter/footnote_filter.rb23
1 files changed, 16 insertions, 7 deletions
diff --git a/lib/banzai/filter/footnote_filter.rb b/lib/banzai/filter/footnote_filter.rb
index 97527976437..de133774dfa 100644
--- a/lib/banzai/filter/footnote_filter.rb
+++ b/lib/banzai/filter/footnote_filter.rb
@@ -29,21 +29,30 @@ module Banzai
# Sanitization stripped off the section wrapper - add it back in
first_footnote.parent.wrap('<section class="footnotes">')
rand_suffix = "-#{random_number}"
+ modified_footnotes = {}
doc.css('sup > a[id]').each do |link_node|
ref_num = link_node[:id].delete_prefix(FOOTNOTE_LINK_ID_PREFIX)
footnote_node = doc.at_css("li[id=#{fn_id(ref_num)}]")
- backref_node = footnote_node.at_css("a[href=\"##{fnref_id(ref_num)}\"]")
- if ref_num =~ INTEGER_PATTERN && footnote_node && backref_node
- link_node[:href] += rand_suffix
- link_node[:id] += rand_suffix
- footnote_node[:id] += rand_suffix
- backref_node[:href] += rand_suffix
+ if INTEGER_PATTERN.match?(ref_num) && (footnote_node || modified_footnotes[ref_num])
+ link_node[:href] += rand_suffix
+ link_node[:id] += rand_suffix
# Sanitization stripped off class - add it back in
link_node.parent.append_class('footnote-ref')
- backref_node.append_class('footnote-backref')
+
+ unless modified_footnotes[ref_num]
+ footnote_node[:id] += rand_suffix
+ backref_node = footnote_node.at_css("a[href=\"##{fnref_id(ref_num)}\"]")
+
+ if backref_node
+ backref_node[:href] += rand_suffix
+ backref_node.append_class('footnote-backref')
+ end
+
+ modified_footnotes[ref_num] = true
+ end
end
end