diff --git a/lib/gitlab/markdown/external_issue_reference_filter.rb b/lib/gitlab/markdown/external_issue_reference_filter.rb index c45cc805c71..cbbadc79847 100644 --- a/lib/gitlab/markdown/external_issue_reference_filter.rb +++ b/lib/gitlab/markdown/external_issue_reference_filter.rb @@ -25,7 +25,8 @@ module Gitlab ISSUE_PATTERN = /(?([A-Z\-]+-)\d+)/ def call - return doc if project.default_issues_tracker? + # Early return if the project isn't using an external tracker + return doc if project.nil? || project.default_issues_tracker? replace_text_nodes_matching(ISSUE_PATTERN) do |content| issue_link_filter(content) diff --git a/lib/gitlab/markdown/reference_filter.rb b/lib/gitlab/markdown/reference_filter.rb index f28f9a1f643..7bd14020ecc 100644 --- a/lib/gitlab/markdown/reference_filter.rb +++ b/lib/gitlab/markdown/reference_filter.rb @@ -42,10 +42,11 @@ module Gitlab # # Returns the updated Nokogiri::XML::Document object. def replace_text_nodes_matching(pattern) + return doc if project.nil? + doc.search('text()').each do |node| content = node.to_html - next if project.nil? next unless content.match(pattern) next if ignored_ancestry?(node) @@ -59,6 +60,9 @@ module Gitlab doc end + # Ensure that a :project key exists in context + # + # Note that while the key might exist, its value could be nil! def validate needs :project end