Commit fa3a637d authored by Markus Koller's avatar Markus Koller

Return nil when fetching a wiki page with invalid arguments

Gitaly returns a GRPC::InvalidArgument response in certain cases, such
as empty titles or versions containing invalid characters.

On the Rails side we don't want to raise an error in this case, but
treat it the same as if a wiki page could not be found.
parent 93758584
---
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
......
......@@ -204,8 +204,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