Gitlab crashes when commit messages reference Github issues
Created by: FooBarWidget
We have a repository in which some commit messages reference Github issues ("Closes GH-1234"). Upon rendering such commit messages, Gitlab crashes. Here is a backtrace:
Started GET "/project/name/commits/tagname" for 82.74.198.138 at 2015-02-13 11:27:59 +0100
Processing by Projects::CommitsController#show as HTML
Parameters: {"project_id"=>"project/name", "id"=>"tagname"}
Completed 500 Internal Server Error in 164ms
ActionView::Template::Error (No route matches {:action=>"show", :controller=>"projects/issues", :id=>"GH-1336", :project_id=>#<Project id: 8, name: "Project", path: "name", description: "...", created_at: "2012-04-24 15:08:48", updated_at: "2014-12-30 14:40:48", creator_id: 1, issues_enabled: true, wall_enabled: false, merge_requests_enabled: true, wiki_enabled: false, namespace_id: 2, issues_tracker: "redmine", issues_tracker_id: "project", snippets_enabled: false, last_activity_at: "2014-12-19 12:16:28", import_url: nil, visibility_level: 0, archived: false, import_status: "none", repository_size: 51.18, star_count: 0>} missing required keys: [:id]):
23: - if commit.description?
24: .commit-row-description.js-toggle-content
25: %pre
26: = preserve(gfm(escape_once(commit.description)))
27:
28: .commit-row-info
29: = commit_author_link(commit, avatar: true, size: 16)
app/helpers/issues_helper.rb:45:in `url_for_issue'
lib/gitlab/markdown.rb:213:in `reference_issue'
lib/gitlab/markdown.rb:195:in `reference_link'
lib/gitlab/markdown.rb:173:in `parse_result'
lib/gitlab/markdown.rb:156:in `block in parse_references'
lib/gitlab/markdown.rb:145:in `gsub!'
lib/gitlab/markdown.rb:145:in `parse_references'
lib/gitlab/markdown.rb:119:in `parse'
lib/gitlab/markdown.rb:66:in `gfm'
app/views/projects/commits/_commit.html.haml:26:in `_app_views_projects_commits__commit_html_haml__138207162263786988_46790160'
app/views/projects/commits/_commits.html.haml:13:in `block in _app_views_projects_commits__commits_html_haml__4608002856175938366_46317140'
app/views/projects/commits/_commits.html.haml:4:in `each'
app/views/projects/commits/_commits.html.haml:4:in `_app_views_projects_commits__commits_html_haml__4608002856175938366_46317140'
app/views/projects/commits/show.html.haml:16:in `_app_views_projects_commits_show_html_haml___1093241592421468883_43655400'
app/controllers/projects/commits_controller.rb:18:in `show'
This crash is caused by the fact that the following method is called:
url = project_issue_url project_id: project, id: issue_iid
Here, issue_iid
is the string "GH-1234". project_issue_url
fails to parse that and thinks the id
parameter is nil, hence the exception.
I've fixed this locally by changing the first line in the url_for_issue
method:
return '' if project.nil? || issue_iid =~ /^GH-/