Commit 8e87e22d authored by Dmytro Zaporozhets's avatar Dmytro Zaporozhets

Merge branch '219546-change-commits_by_message-encoding-method-to-not-mutate-string' into 'master'

Change `commits_by_message` to not mutate string parameters

Closes #219546

See merge request gitlab-org/gitlab!33540
parents 5420d266 1ac20461
...@@ -247,8 +247,8 @@ module Gitlab ...@@ -247,8 +247,8 @@ module Gitlab
request = Gitaly::CommitsByMessageRequest.new( request = Gitaly::CommitsByMessageRequest.new(
repository: @gitaly_repo, repository: @gitaly_repo,
query: query, query: query,
revision: revision.to_s.force_encoding(Encoding::ASCII_8BIT), revision: encode_binary(revision),
path: path.to_s.force_encoding(Encoding::ASCII_8BIT), path: encode_binary(path),
limit: limit.to_i, limit: limit.to_i,
offset: offset.to_i offset: offset.to_i
) )
......
...@@ -326,4 +326,59 @@ describe Gitlab::GitalyClient::CommitService do ...@@ -326,4 +326,59 @@ describe Gitlab::GitalyClient::CommitService do
client.find_commits(order: 'default', author: "Billy Baggins <bilbo@shire.com>") client.find_commits(order: 'default', author: "Billy Baggins <bilbo@shire.com>")
end end
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 end
...@@ -532,7 +532,7 @@ describe Gitlab::ProjectSearchResults do ...@@ -532,7 +532,7 @@ describe Gitlab::ProjectSearchResults do
context 'when repository_ref is provided' do context 'when repository_ref is provided' do
let(:message) { 'Feature added' } let(:message) { 'Feature added' }
let(:repository_ref) { +'feature' } let(:repository_ref) { 'feature' }
it 'searches in the specified ref' do it 'searches in the specified ref' do
commits = described_class.new(user, project, message, repository_ref).objects('commits') 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