提交 06a226a1 编写于 作者: S Sean McGivern

Fix code and wiki search results when filename is non-ASCII

Previously, we only handled non-ASCII file contents, but the name itself can be
non-ASCII.
上级 d47449e9
---
title: Fix code and wiki search results when filename is non-ASCII
merge_request:
author:
type: fixed
...@@ -7,8 +7,8 @@ module Gitlab ...@@ -7,8 +7,8 @@ module Gitlab
def initialize(opts = {}) def initialize(opts = {})
@id = opts.fetch(:id, nil) @id = opts.fetch(:id, nil)
@filename = opts.fetch(:filename, nil) @filename = encode_utf8(opts.fetch(:filename, nil))
@basename = opts.fetch(:basename, nil) @basename = encode_utf8(opts.fetch(:basename, nil))
@ref = opts.fetch(:ref, nil) @ref = opts.fetch(:ref, nil)
@startline = opts.fetch(:startline, nil) @startline = opts.fetch(:startline, nil)
@data = encode_utf8(opts.fetch(:data, nil)) @data = encode_utf8(opts.fetch(:data, nil))
......
...@@ -108,14 +108,26 @@ describe Gitlab::ProjectSearchResults do ...@@ -108,14 +108,26 @@ describe Gitlab::ProjectSearchResults do
context 'when the search returns non-ASCII data' do context 'when the search returns non-ASCII data' do
context 'with UTF-8' do context 'with UTF-8' do
let(:results) { project.repository.search_files_by_content("файл", 'master') } let(:results) { project.repository.search_files_by_content('файл', 'master') }
it 'returns results as UTF-8' do it 'returns results as UTF-8' do
expect(subject.filename).to eq('encoding/russian.rb') expect(subject.filename).to eq('encoding/russian.rb')
expect(subject.basename).to eq('encoding/russian') expect(subject.basename).to eq('encoding/russian')
expect(subject.ref).to eq('master') expect(subject.ref).to eq('master')
expect(subject.startline).to eq(1) expect(subject.startline).to eq(1)
expect(subject.data).to eq("Хороший файл") expect(subject.data).to eq('Хороший файл')
end
end
context 'with UTF-8 in the filename' do
let(:results) { project.repository.search_files_by_content('webhook', 'master') }
it 'returns results as UTF-8' do
expect(subject.filename).to eq('encoding/テスト.txt')
expect(subject.basename).to eq('encoding/テスト')
expect(subject.ref).to eq('master')
expect(subject.startline).to eq(3)
expect(subject.data).to include('WebHookの確認')
end end
end end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册