Skip to content
代码片段 群组 项目
提交 31744141 编辑于 作者: Vasilii Iakliushin's avatar Vasilii Iakliushin
浏览文件

Fix encoding error for commits endpoint

Contributes to https://gitlab.com/gitlab-org/gitlab/-/issues/407848

**Problem**

We started displaying tags on commits page. However, tags with UTF-8
characters raise an exception, because we don't encode them correctly.

**Solution**

Use 'Git#ref_name' to convert tag name to UTF-8 format.

Changelog: fixed
上级 2360bb39
No related branches found
No related tags found
无相关合并请求
......@@ -26,7 +26,7 @@ def any_pipelines?
end
def tags_for_display
commit.referenced_by&.map { |tag| tag.delete_prefix(Gitlab::Git::TAG_REF_PREFIX) }
commit.referenced_by&.map { |tag_name| Gitlab::Git.ref_name(tag_name) }
end
def signature_html
......
......@@ -3,8 +3,9 @@
require 'spec_helper'
RSpec.describe Projects::CommitsController, feature_category: :source_code_management do
let(:project) { create(:project, :repository) }
let(:user) { create(:user) }
let_it_be(:project) { create(:project, :repository) }
let_it_be(:repository) { project.repository }
let_it_be(:user) { create(:user) }
before do
project.add_maintainer(user)
......@@ -105,7 +106,22 @@
expect_next_instance_of(CommitCollection) do |collection|
expect(collection).to receive(:load_tags)
end
get :show, params: { namespace_id: project.namespace, project_id: project, id: 'master/README.md' }
expect(response).to have_gitlab_http_status(:ok)
end
context 'when tag has a non-ASCII encoding' do
before do
repository.add_tag(user, 'tést', 'master')
end
it 'does not raise an exception' do
get :show, params: { namespace_id: project.namespace, project_id: project, id: 'master' }
expect(response).to have_gitlab_http_status(:ok)
end
end
context 'when the show_tags_on_commits_view flag is disabled' do
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册