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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
ce46b402
Commit
ce46b402
authored
Sep 10, 2019
by
Hiroyuki Sato
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix encoding error in MR diffs
parent
e47cbf37
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
52 additions
and
14 deletions
+52
-14
app/models/merge_request_diff_file.rb
app/models/merge_request_diff_file.rb
+1
-1
changelogs/unreleased/61841-fix-encoding-error-in-mr-diffs.yml
...elogs/unreleased/61841-fix-encoding-error-in-mr-diffs.yml
+5
-0
spec/models/merge_request_diff_file_spec.rb
spec/models/merge_request_diff_file_spec.rb
+46
-13
No files found.
app/models/merge_request_diff_file.rb
View file @
ce46b402
...
@@ -17,7 +17,7 @@ class MergeRequestDiffFile < ApplicationRecord
...
@@ -17,7 +17,7 @@ class MergeRequestDiffFile < ApplicationRecord
if
merge_request_diff
&
.
stored_externally?
if
merge_request_diff
&
.
stored_externally?
merge_request_diff
.
opening_external_diff
do
|
file
|
merge_request_diff
.
opening_external_diff
do
|
file
|
file
.
seek
(
external_diff_offset
)
file
.
seek
(
external_diff_offset
)
f
ile
.
read
(
external_diff_size
)
f
orce_encode_utf8
(
file
.
read
(
external_diff_size
)
)
end
end
else
else
super
super
...
...
changelogs/unreleased/61841-fix-encoding-error-in-mr-diffs.yml
0 → 100644
View file @
ce46b402
---
title
:
Fix encoding error in MR diffs when using external diffs
merge_request
:
32862
author
:
Hiroyuki Sato
type
:
fixed
spec/models/merge_request_diff_file_spec.rb
View file @
ce46b402
...
@@ -4,6 +4,7 @@ require 'spec_helper'
...
@@ -4,6 +4,7 @@ require 'spec_helper'
describe
MergeRequestDiffFile
do
describe
MergeRequestDiffFile
do
describe
'#diff'
do
describe
'#diff'
do
context
'when diff is not stored'
do
let
(
:unpacked
)
{
'unpacked'
}
let
(
:unpacked
)
{
'unpacked'
}
let
(
:packed
)
{
[
unpacked
].
pack
(
'm0'
)
}
let
(
:packed
)
{
[
unpacked
].
pack
(
'm0'
)
}
...
@@ -28,6 +29,38 @@ describe MergeRequestDiffFile do
...
@@ -28,6 +29,38 @@ describe MergeRequestDiffFile do
end
end
end
end
context
'when diff is stored in DB'
do
let
(
:file
)
{
create
(
:merge_request
).
merge_request_diff
.
merge_request_diff_files
.
first
}
it
'returns UTF-8 string'
do
expect
(
file
.
diff
.
encoding
).
to
eq
Encoding
::
UTF_8
end
end
context
'when diff is stored in external storage'
do
let
(
:file
)
{
create
(
:merge_request
).
merge_request_diff
.
merge_request_diff_files
.
first
}
let
(
:test_dir
)
{
'tmp/tests/external-diffs'
}
around
do
|
example
|
FileUtils
.
mkdir_p
(
test_dir
)
begin
example
.
run
ensure
FileUtils
.
rm_rf
(
test_dir
)
end
end
before
do
stub_external_diffs_setting
(
enabled:
true
,
storage_path:
test_dir
)
end
it
'returns UTF-8 string'
do
expect
(
file
.
diff
.
encoding
).
to
eq
Encoding
::
UTF_8
end
end
end
describe
'#utf8_diff'
do
describe
'#utf8_diff'
do
it
'does not raise error when the diff is binary'
do
it
'does not raise error when the diff is binary'
do
subject
.
diff
=
"
\x05\x00\x68\x65\x6c\x6c\x6f
"
subject
.
diff
=
"
\x05\x00\x68\x65\x6c\x6c\x6f
"
...
...
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