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
ca4ba45b
Commit
ca4ba45b
authored
Sep 19, 2020
by
Nick Thomas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix encoding detection for nil diffs
parent
ced482c7
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
1 deletion
+19
-1
app/models/merge_request_diff.rb
app/models/merge_request_diff.rb
+3
-1
changelogs/unreleased/fix-encoding-for-nil-diff-files.yml
changelogs/unreleased/fix-encoding-for-nil-diff-files.yml
+5
-0
spec/models/merge_request_diff_spec.rb
spec/models/merge_request_diff_spec.rb
+11
-0
No files found.
app/models/merge_request_diff.rb
View file @
ca4ba45b
...
...
@@ -509,6 +509,8 @@ class MergeRequestDiff < ApplicationRecord
end
def
encode_in_base64?
(
diff_text
)
return
false
if
diff_text
.
nil?
(
diff_text
.
encoding
==
Encoding
::
BINARY
&&
!
diff_text
.
ascii_only?
)
||
diff_text
.
include?
(
"
\0
"
)
end
...
...
@@ -536,7 +538,7 @@ class MergeRequestDiff < ApplicationRecord
rows
.
each
do
|
row
|
data
=
row
.
delete
(
:diff
)
row
[
:external_diff_offset
]
=
file
.
pos
row
[
:external_diff_size
]
=
data
.
bytesize
row
[
:external_diff_size
]
=
data
&
.
bytesize
||
0
file
.
write
(
data
)
end
...
...
changelogs/unreleased/fix-encoding-for-nil-diff-files.yml
0 → 100644
View file @
ca4ba45b
---
title
:
Fix migrating some empty diffs
merge_request
:
42825
author
:
type
:
fixed
spec/models/merge_request_diff_spec.rb
View file @
ca4ba45b
...
...
@@ -180,6 +180,17 @@ RSpec.describe MergeRequestDiff do
expect
(
diff
.
external_diff_store
).
to
eq
(
file_store
)
end
it
'migrates a nil diff file'
do
expect
(
diff
).
not_to
be_stored_externally
MergeRequestDiffFile
.
where
(
merge_request_diff_id:
diff
.
id
).
update_all
(
diff:
nil
)
stub_external_diffs_setting
(
enabled:
true
)
diff
.
migrate_files_to_external_storage!
expect
(
diff
).
to
be_stored_externally
end
it
'safely handles a transaction error when migrating to external storage'
do
expect
(
diff
).
not_to
be_stored_externally
expect
(
diff
.
external_diff
).
not_to
be_exists
...
...
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