Commit 2c3abd36 authored by Stan Hu's avatar Stan Hu

Merge branch '222699-wiki-find-page-empty-title' into 'master'

Return nil when fetching a wiki page with invalid arguments

See merge request gitlab-org/gitlab!44302
parents 5d9cd03c fa3a637d
---
title: Return nil when fetching a wiki page with invalid arguments
merge_request: 44302
author:
type: fixed
......@@ -100,10 +100,6 @@ module Gitlab
wrapped_gitaly_errors do
gitaly_find_page(title: title, version: version, dir: dir)
end
rescue Gitlab::Git::CommandError
# Return nil for invalid versions.
# This can be removed with https://gitlab.com/gitlab-org/gitaly/-/merge_requests/2323 in place.
nil
end
def file(name, version)
......@@ -159,6 +155,8 @@ module Gitlab
return unless wiki_page
Gitlab::Git::WikiPage.new(wiki_page, version)
rescue GRPC::InvalidArgument
nil
end
def gitaly_find_file(name, version)
......
......@@ -51,6 +51,11 @@ RSpec.describe Gitlab::Git::Wiki do
expect(subject.page(title: 'page1', dir: '').url_path).to eq 'page1'
expect(subject.page(title: 'page1', dir: 'foo').url_path).to eq 'foo/page1'
end
it 'returns nil for invalid arguments' do
expect(subject.page(title: '')).to be_nil
expect(subject.page(title: 'foo', version: ':')).to be_nil
end
end
describe '#delete_page' do
......
......@@ -282,8 +282,9 @@ RSpec.shared_examples 'wiki model' do
expect(page.title).to eq('index page')
end
it 'returns nil if the page does not exist' do
expect(subject.find_page('non-existent')).to eq(nil)
it 'returns nil if the page or version does not exist' do
expect(subject.find_page('non-existent')).to be_nil
expect(subject.find_page('index page', 'non-existent')).to be_nil
end
it 'can find a page by slug' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment