Commit 1ac20461 authored by Alishan Ladhani's avatar Alishan Ladhani

Don't mutate string parameters

To avoid errors when the strings are immutable.
See https://gitlab.com/gitlab-org/gitlab/-/merge_requests/33216#note_351391995
parent 1b0d7e52
......@@ -247,8 +247,8 @@ module Gitlab
request = Gitaly::CommitsByMessageRequest.new(
repository: @gitaly_repo,
query: query,
revision: revision.to_s.force_encoding(Encoding::ASCII_8BIT),
path: path.to_s.force_encoding(Encoding::ASCII_8BIT),
revision: encode_binary(revision),
path: encode_binary(path),
limit: limit.to_i,
offset: offset.to_i
)
......
......@@ -326,4 +326,59 @@ describe Gitlab::GitalyClient::CommitService do
client.find_commits(order: 'default', author: "Billy Baggins <bilbo@shire.com>")
end
end
describe '#commits_by_message' do
shared_examples 'a CommitsByMessageRequest' do
let(:commits) { create_list(:gitaly_commit, 2) }
before do
request = Gitaly::CommitsByMessageRequest.new(
repository: repository_message,
query: query,
revision: (options[:revision] || '').dup.force_encoding(Encoding::ASCII_8BIT),
path: (options[:path] || '').dup.force_encoding(Encoding::ASCII_8BIT),
limit: (options[:limit] || 1000).to_i,
offset: (options[:offset] || 0).to_i
)
allow_any_instance_of(Gitaly::CommitService::Stub)
.to receive(:commits_by_message)
.with(request, kind_of(Hash))
.and_return([Gitaly::CommitsByMessageResponse.new(commits: commits)])
end
it 'sends an RPC request with the correct payload' do
expect(client.commits_by_message(query, options)).to match_array(wrap_commits(commits))
end
end
let(:query) { 'Add a feature' }
let(:options) { {} }
context 'when only the query is provided' do
include_examples 'a CommitsByMessageRequest'
end
context 'when all arguments are provided' do
let(:options) { { revision: 'feature-branch', path: 'foo.txt', limit: 10, offset: 20 } }
include_examples 'a CommitsByMessageRequest'
end
context 'when limit and offset are not integers' do
let(:options) { { limit: '10', offset: '60' } }
include_examples 'a CommitsByMessageRequest'
end
context 'when revision and path contain non-ASCII characters' do
let(:options) { { revision: "branch\u011F", path: "foo/\u011F.txt" } }
include_examples 'a CommitsByMessageRequest'
end
def wrap_commits(commits)
commits.map { |commit| Gitlab::Git::Commit.new(repository, commit) }
end
end
end
......@@ -532,7 +532,7 @@ describe Gitlab::ProjectSearchResults do
context 'when repository_ref is provided' do
let(:message) { 'Feature added' }
let(:repository_ref) { +'feature' }
let(:repository_ref) { 'feature' }
it 'searches in the specified ref' do
commits = described_class.new(user, project, message, repository_ref).objects('commits')
......
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