BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
b3c096cd
Commit
b3c096cd
authored
Feb 28, 2018
by
Sean McGivern
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix code search results with non-ASCII data
Gitlab::Git::Popen#popen now returns ASCII-8BIT (binary) data always, so we need to handle that explicitly.
parent
4371f845
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
1 deletion
+35
-1
43531-500-error-searching-wiki-incompatible-character-encodings-utf-8-and-ascii-8bit.yml
...incompatible-character-encodings-utf-8-and-ascii-8bit.yml
+5
-0
search_results.rb
lib/gitlab/search_results.rb
+3
-1
project_search_results_spec.rb
spec/lib/gitlab/project_search_results_spec.rb
+27
-0
No files found.
changelogs/unreleased/43531-500-error-searching-wiki-incompatible-character-encodings-utf-8-and-ascii-8bit.yml
0 → 100644
View file @
b3c096cd
---
title
:
Fix code and wiki search results pages when non-ASCII text is displayed
merge_request
:
17413
author
:
type
:
fixed
lib/gitlab/search_results.rb
View file @
b3c096cd
module
Gitlab
class
SearchResults
class
FoundBlob
include
EncodingHelper
attr_reader
:id
,
:filename
,
:basename
,
:ref
,
:startline
,
:data
,
:project_id
def
initialize
(
opts
=
{})
...
...
@@ -9,7 +11,7 @@ module Gitlab
@basename
=
opts
.
fetch
(
:basename
,
nil
)
@ref
=
opts
.
fetch
(
:ref
,
nil
)
@startline
=
opts
.
fetch
(
:startline
,
nil
)
@data
=
opts
.
fetch
(
:data
,
nil
)
@data
=
encode_utf8
(
opts
.
fetch
(
:data
,
nil
)
)
@per_page
=
opts
.
fetch
(
:per_page
,
20
)
@project_id
=
opts
.
fetch
(
:project_id
,
nil
)
end
...
...
spec/lib/gitlab/project_search_results_spec.rb
View file @
b3c096cd
# coding: utf-8
require
'spec_helper'
describe
Gitlab
::
ProjectSearchResults
do
...
...
@@ -105,6 +106,32 @@ describe Gitlab::ProjectSearchResults do
end
end
context
'when the search returns non-ASCII data'
do
context
'with UTF-8'
do
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
(
"Хороший файл"
)
end
end
context
'with ISO-8859-1'
do
let
(
:search_result
)
{
"master:encoding/iso8859.txt
\x00
1
\x00\xC4\xFC\n
master:encoding/iso8859.txt
\x00
2
\x00\n
master:encoding/iso8859.txt
\x00
3
\x00
foo
\n
"
.
force_encoding
(
Encoding
::
ASCII_8BIT
)
}
it
'returns results as UTF-8'
do
expect
(
subject
.
filename
).
to
eq
(
'encoding/iso8859.txt'
)
expect
(
subject
.
basename
).
to
eq
(
'encoding/iso8859'
)
expect
(
subject
.
ref
).
to
eq
(
'master'
)
expect
(
subject
.
startline
).
to
eq
(
1
)
expect
(
subject
.
data
).
to
eq
(
"Äü
\n\n
foo"
)
end
end
end
context
"when filename has extension"
do
let
(
:search_result
)
{
"master:CONTRIBUTE.md
\x00
5
\x00
- [Contribute to GitLab](#contribute-to-gitlab)
\n
"
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment