diff options
author | Nick Thomas <nick@gitlab.com> | 2018-10-15 22:07:02 +0300 |
---|---|---|
committer | Nick Thomas <nick@gitlab.com> | 2018-10-17 15:24:52 +0300 |
commit | d66066f7cb4a2981c74224ad2cb6ec3c00ca529e (patch) | |
tree | e416f31d864631ad9b231870eb8bae46d2234aac /app | |
parent | e657c9a9e6d9877a4bf0b3fb39a0f4bff0dc5470 (diff) |
Harden the wiki against missing last_versions
Currently, we assume a "last_version" always exists for a wiki page.
In production, this is not always true. So, guard uses of it with a
null check.
Diffstat (limited to 'app')
-rw-r--r-- | app/models/wiki_page.rb | 4 | ||||
-rw-r--r-- | app/views/projects/wikis/_pages_wiki_page.html.haml | 3 | ||||
-rw-r--r-- | app/views/projects/wikis/show.html.haml | 5 |
3 files changed, 8 insertions, 4 deletions
diff --git a/app/models/wiki_page.rb b/app/models/wiki_page.rb index 42fd213d03b..c5e349ae913 100644 --- a/app/models/wiki_page.rb +++ b/app/models/wiki_page.rb @@ -160,7 +160,9 @@ class WikiPage # Returns boolean True or False if this instance # is an old version of the page. def historical? - @page.historical? && last_version.sha != version.sha + return false unless last_commit_sha && version + + @page.historical? && last_commit_sha != version.sha end # Returns boolean True or False if this instance diff --git a/app/views/projects/wikis/_pages_wiki_page.html.haml b/app/views/projects/wikis/_pages_wiki_page.html.haml index cbb441d7509..c156f8cbf50 100644 --- a/app/views/projects/wikis/_pages_wiki_page.html.haml +++ b/app/views/projects/wikis/_pages_wiki_page.html.haml @@ -2,4 +2,5 @@ = link_to wiki_page.title, project_wiki_path(@project, wiki_page) %small (#{wiki_page.format}) .float-right - %small= (s_("Last edited %{date}") % { date: time_ago_with_tooltip(wiki_page.last_version.authored_date) }).html_safe + - if wiki_page.last_version + %small= (s_("Last edited %{date}") % { date: time_ago_with_tooltip(wiki_page.last_version.authored_date) }).html_safe diff --git a/app/views/projects/wikis/show.html.haml b/app/views/projects/wikis/show.html.haml index 19b9744b508..fbf248c2058 100644 --- a/app/views/projects/wikis/show.html.haml +++ b/app/views/projects/wikis/show.html.haml @@ -11,8 +11,9 @@ .nav-text %h2.wiki-page-title= @page.title.capitalize %span.wiki-last-edit-by - = (_("Last edited by %{name}") % { name: "<strong>#{@page.last_version.author_name}</strong>" }).html_safe - #{time_ago_with_tooltip(@page.last_version.authored_date)} + - if @page.last_version + = (_("Last edited by %{name}") % { name: "<strong>#{@page.last_version.author_name}</strong>" }).html_safe + #{time_ago_with_tooltip(@page.last_version.authored_date)} .nav-controls = render 'main_links' |