Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Jérome Perrin
gitlab-ce
Commits
4cfcc975
Commit
4cfcc975
authored
Nov 23, 2017
by
Jacob Vosmaer (GitLab)
Committed by
Rémy Coutable
Nov 23, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix encoding bugs in Gitlab::Git::User
parent
ffa2a980
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
32 additions
and
8 deletions
+32
-8
lib/gitlab/encoding_helper.rb
lib/gitlab/encoding_helper.rb
+4
-0
lib/gitlab/git/user.rb
lib/gitlab/git/user.rb
+7
-2
spec/lib/gitlab/encoding_helper_spec.rb
spec/lib/gitlab/encoding_helper_spec.rb
+1
-0
spec/lib/gitlab/git/user_spec.rb
spec/lib/gitlab/git/user_spec.rb
+11
-6
spec/support/matchers/be_a_binary_string.rb
spec/support/matchers/be_a_binary_string.rb
+9
-0
No files found.
lib/gitlab/encoding_helper.rb
View file @
4cfcc975
...
...
@@ -17,6 +17,10 @@ module Gitlab
return
nil
unless
message
.
respond_to?
(
:force_encoding
)
return
message
if
message
.
encoding
==
Encoding
::
UTF_8
&&
message
.
valid_encoding?
if
message
.
respond_to?
(
:frozen?
)
&&
message
.
frozen?
message
=
message
.
dup
end
message
.
force_encoding
(
"UTF-8"
)
return
message
if
message
.
valid_encoding?
...
...
lib/gitlab/git/user.rb
View file @
4cfcc975
...
...
@@ -8,7 +8,12 @@ module Gitlab
end
def
self
.
from_gitaly
(
gitaly_user
)
new
(
gitaly_user
.
gl_username
,
gitaly_user
.
name
,
gitaly_user
.
email
,
gitaly_user
.
gl_id
)
new
(
gitaly_user
.
gl_username
,
Gitlab
::
EncodingHelper
.
encode!
(
gitaly_user
.
name
),
Gitlab
::
EncodingHelper
.
encode!
(
gitaly_user
.
email
),
gitaly_user
.
gl_id
)
end
def
initialize
(
username
,
name
,
email
,
gl_id
)
...
...
@@ -23,7 +28,7 @@ module Gitlab
end
def
to_gitaly
Gitaly
::
User
.
new
(
gl_username:
username
,
gl_id:
gl_id
,
name:
name
,
email:
email
)
Gitaly
::
User
.
new
(
gl_username:
username
,
gl_id:
gl_id
,
name:
name
.
b
,
email:
email
.
b
)
end
end
end
...
...
spec/lib/gitlab/encoding_helper_spec.rb
View file @
4cfcc975
...
...
@@ -9,6 +9,7 @@ describe Gitlab::EncodingHelper do
[
"nil"
,
nil
,
nil
],
[
"empty string"
,
""
.
encode
(
"ASCII-8BIT"
),
""
.
encode
(
"UTF-8"
)],
[
"invalid utf-8 encoded string"
,
"my bad string
\xE5
"
.
force_encoding
(
"UTF-8"
),
"my bad string"
],
[
"frozen non-ascii string"
,
"é"
.
force_encoding
(
"ASCII-8BIT"
).
freeze
,
"é"
.
encode
(
"UTF-8"
)],
[
'leaves ascii only string as is'
,
'ascii only string'
,
...
...
spec/lib/gitlab/git/user_spec.rb
View file @
4cfcc975
require
'spec_helper'
describe
Gitlab
::
Git
::
User
do
let
(
:username
)
{
'janedo'
}
let
(
:name
)
{
'Jane Do
e
'
}
let
(
:email
)
{
'janedo
e
@example.com'
}
let
(
:username
)
{
'janedo
e
'
}
let
(
:name
)
{
'Jane Do
é
'
}
let
(
:email
)
{
'janedo
é
@example.com'
}
let
(
:gl_id
)
{
'user-123'
}
let
(
:user
)
do
described_class
.
new
(
username
,
name
,
email
,
gl_id
)
...
...
@@ -13,7 +13,7 @@ describe Gitlab::Git::User do
describe
'.from_gitaly'
do
let
(
:gitaly_user
)
do
Gitaly
::
User
.
new
(
gl_username:
username
,
name:
name
,
email:
email
,
gl_id:
gl_id
)
Gitaly
::
User
.
new
(
gl_username:
username
,
name:
name
.
b
,
email:
email
.
b
,
gl_id:
gl_id
)
end
subject
{
described_class
.
from_gitaly
(
gitaly_user
)
}
...
...
@@ -48,8 +48,13 @@ describe Gitlab::Git::User do
it
'creates a Gitaly::User with the correct data'
do
expect
(
subject
).
to
be_a
(
Gitaly
::
User
)
expect
(
subject
.
gl_username
).
to
eq
(
username
)
expect
(
subject
.
name
).
to
eq
(
name
)
expect
(
subject
.
email
).
to
eq
(
email
)
expect
(
subject
.
name
).
to
eq
(
name
.
b
)
expect
(
subject
.
name
).
to
be_a_binary_string
expect
(
subject
.
email
).
to
eq
(
email
.
b
)
expect
(
subject
.
email
).
to
be_a_binary_string
expect
(
subject
.
gl_id
).
to
eq
(
gl_id
)
end
end
...
...
spec/support/matchers/be_a_binary_string.rb
0 → 100644
View file @
4cfcc975
RSpec
::
Matchers
.
define
:be_a_binary_string
do
|
_
|
match
do
|
actual
|
actual
.
is_a?
(
String
)
&&
actual
.
encoding
==
Encoding
.
find
(
'ASCII-8BIT'
)
end
description
do
"be a String with binary encoding"
end
end
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