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.
This commit is contained in:
parent
d47449e957
commit
06a226a1c0
3 changed files with 21 additions and 4 deletions
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
title: Fix code and wiki search results when filename is non-ASCII
|
||||
merge_request:
|
||||
author:
|
||||
type: fixed
|
|
@ -7,8 +7,8 @@ module Gitlab
|
|||
|
||||
def initialize(opts = {})
|
||||
@id = opts.fetch(:id, nil)
|
||||
@filename = opts.fetch(:filename, nil)
|
||||
@basename = opts.fetch(:basename, nil)
|
||||
@filename = encode_utf8(opts.fetch(:filename, nil))
|
||||
@basename = encode_utf8(opts.fetch(:basename, nil))
|
||||
@ref = opts.fetch(:ref, nil)
|
||||
@startline = opts.fetch(:startline, nil)
|
||||
@data = encode_utf8(opts.fetch(:data, nil))
|
||||
|
|
|
@ -108,14 +108,26 @@ describe Gitlab::ProjectSearchResults do
|
|||
|
||||
context 'when the search returns non-ASCII data' 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
|
||||
expect(subject.filename).to eq('encoding/russian.rb')
|
||||
expect(subject.basename).to eq('encoding/russian')
|
||||
expect(subject.ref).to eq('master')
|
||||
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
|
||||
|
||||
|
|
Loading…
Reference in a new issue