summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRobert Speicher <rspeicher@gmail.com>2015-04-15 13:04:04 -0400
committerRobert Speicher <rspeicher@gmail.com>2015-04-20 13:01:46 -0400
commit31172475d220f7681abac0e46a171e315fdcfadc (patch)
tree55c71828159ad22741245c899bf1384f2b3744fe /lib
parent9eaaa7cdef124d73b1c6b98e7af7a4fc18a76cf3 (diff)
downloadgitlab-ce-31172475d220f7681abac0e46a171e315fdcfadc.tar.gz
Better guard against nil projects in ReferenceFilter
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/markdown/external_issue_reference_filter.rb3
-rw-r--r--lib/gitlab/markdown/reference_filter.rb6
2 files changed, 7 insertions, 2 deletions
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 = /(?<issue>([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