summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzegorz@gitlab.com>2016-04-21 08:13:12 +0000
committerYorick Peterse <yorickpeterse@gmail.com>2016-04-21 10:26:36 +0000
commitad016cbd8689afc92c83f7347daffbcd7ea2dcb1 (patch)
treeb97961838f046ebd295c35f2c4bd6093ebe13b10 /lib
parent15f62ed65f55b2db208e4b5897d393fa8623e238 (diff)
downloadgitlab-ce-ad016cbd8689afc92c83f7347daffbcd7ea2dcb1.tar.gz
Merge branch 'fix/cross-project-labels-project-reference' into 'master'
Fix cross-project label ref used with invalid project When cross-project label reference was used with invalid project reference, `nil` was assigned to project variable which later caused an exception. Closes #15168 See merge request !3811
Diffstat (limited to 'lib')
-rw-r--r--lib/banzai/filter/label_reference_filter.rb36
1 files changed, 21 insertions, 15 deletions
diff --git a/lib/banzai/filter/label_reference_filter.rb b/lib/banzai/filter/label_reference_filter.rb
index a2987850d03..8488a493b55 100644
--- a/lib/banzai/filter/label_reference_filter.rb
+++ b/lib/banzai/filter/label_reference_filter.rb
@@ -18,9 +18,7 @@ module Banzai
def references_in(text, pattern = Label.reference_pattern)
text.gsub(pattern) do |match|
- project = project_from_ref($~[:project])
- params = label_params($~[:label_id].to_i, $~[:label_name])
- label = project.labels.find_by(params)
+ label = find_label($~[:project], $~[:label_id], $~[:label_name])
if label
yield match, label.id, $~[:project], $~
@@ -30,18 +28,12 @@ module Banzai
end
end
- def url_for_object(label, project)
- h = Gitlab::Routing.url_helpers
- h.namespace_project_issues_url(project.namespace, project, label_name: label.name,
- only_path: context[:only_path])
- end
+ def find_label(project_ref, label_id, label_name)
+ project = project_from_ref(project_ref)
+ return unless project
- def object_link_text(object, matches)
- if context[:project] == object.project
- LabelsHelper.render_colored_label(object)
- else
- LabelsHelper.render_colored_cross_project_label(object)
- end
+ label_params = label_params(label_id, label_name)
+ project.labels.find_by(label_params)
end
# Parameters to pass to `Label.find_by` based on the given arguments
@@ -55,7 +47,21 @@ module Banzai
if name
{ name: name.tr('"', '') }
else
- { id: id }
+ { id: id.to_i }
+ end
+ end
+
+ def url_for_object(label, project)
+ h = Gitlab::Routing.url_helpers
+ h.namespace_project_issues_url(project.namespace, project, label_name: label.name,
+ only_path: context[:only_path])
+ end
+
+ def object_link_text(object, matches)
+ if context[:project] == object.project
+ LabelsHelper.render_colored_label(object)
+ else
+ LabelsHelper.render_colored_cross_project_label(object)
end
end
end