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
a19c6342
Commit
a19c6342
authored
Mar 15, 2019
by
GitLab Bot
Browse files
Options
Browse Files
Download
Plain Diff
Automatic merge of gitlab-org/gitlab-ce master
parents
8dee4cba
a885e2d0
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
46 additions
and
1 deletion
+46
-1
app/models/merge_request_diff.rb
app/models/merge_request_diff.rb
+6
-1
changelogs/unreleased/sh-handle-null-bytes-in-merge-request-diffs.yml
...nreleased/sh-handle-null-bytes-in-merge-request-diffs.yml
+5
-0
spec/models/merge_request_diff_spec.rb
spec/models/merge_request_diff_spec.rb
+21
-0
spec/support/helpers/repo_helpers.rb
spec/support/helpers/repo_helpers.rb
+14
-0
No files found.
app/models/merge_request_diff.rb
View file @
a19c6342
...
@@ -296,6 +296,11 @@ class MergeRequestDiff < ActiveRecord::Base
...
@@ -296,6 +296,11 @@ class MergeRequestDiff < ActiveRecord::Base
private
private
def
encode_in_base64?
(
diff_text
)
(
diff_text
.
encoding
==
Encoding
::
BINARY
&&
!
diff_text
.
ascii_only?
)
||
diff_text
.
include?
(
"
\0
"
)
end
def
create_merge_request_diff_files
(
diffs
)
def
create_merge_request_diff_files
(
diffs
)
rows
=
rows
=
if
has_attribute?
(
:external_diff
)
&&
Gitlab
.
config
.
external_diffs
.
enabled
if
has_attribute?
(
:external_diff
)
&&
Gitlab
.
config
.
external_diffs
.
enabled
...
@@ -348,7 +353,7 @@ class MergeRequestDiff < ActiveRecord::Base
...
@@ -348,7 +353,7 @@ class MergeRequestDiff < ActiveRecord::Base
diff_hash
.
tap
do
|
hash
|
diff_hash
.
tap
do
|
hash
|
diff_text
=
hash
[
:diff
]
diff_text
=
hash
[
:diff
]
if
diff_text
.
encoding
==
Encoding
::
BINARY
&&
!
diff_text
.
ascii_only?
if
encode_in_base64?
(
diff_text
)
hash
[
:binary
]
=
true
hash
[
:binary
]
=
true
hash
[
:diff
]
=
[
diff_text
].
pack
(
'm0'
)
hash
[
:diff
]
=
[
diff_text
].
pack
(
'm0'
)
end
end
...
...
changelogs/unreleased/sh-handle-null-bytes-in-merge-request-diffs.yml
0 → 100644
View file @
a19c6342
---
title
:
Fix error creating a merge request when diff includes a
null
byte
merge_request
:
26190
author
:
type
:
fixed
spec/models/merge_request_diff_spec.rb
View file @
a19c6342
require
'spec_helper'
require
'spec_helper'
describe
MergeRequestDiff
do
describe
MergeRequestDiff
do
include
RepoHelpers
let
(
:diff_with_commits
)
{
create
(
:merge_request
).
merge_request_diff
}
let
(
:diff_with_commits
)
{
create
(
:merge_request
).
merge_request_diff
}
describe
'validations'
do
describe
'validations'
do
...
@@ -194,6 +196,25 @@ describe MergeRequestDiff do
...
@@ -194,6 +196,25 @@ describe MergeRequestDiff do
expect
(
diff_file
).
to
be_binary
expect
(
diff_file
).
to
be_binary
expect
(
diff_file
.
diff
).
to
eq
(
mr_diff
.
compare
.
diffs
(
paths:
[
path
]).
to_a
.
first
.
diff
)
expect
(
diff_file
.
diff
).
to
eq
(
mr_diff
.
compare
.
diffs
(
paths:
[
path
]).
to_a
.
first
.
diff
)
end
end
context
'with diffs that contain a null byte'
do
let
(
:filename
)
{
'test-null.txt'
}
let
(
:content
)
{
"a"
*
10000
+
"
\x00
"
}
let
(
:project
)
{
create
(
:project
,
:repository
)
}
let
(
:branch
)
{
'null-data'
}
let
(
:target_branch
)
{
'master'
}
it
'saves diffs correctly'
do
create_file_in_repo
(
project
,
target_branch
,
branch
,
filename
,
content
)
mr_diff
=
create
(
:merge_request
,
target_project:
project
,
source_project:
project
,
source_branch:
branch
,
target_branch:
target_branch
).
merge_request_diff
diff_file
=
mr_diff
.
merge_request_diff_files
.
find_by
(
new_path:
filename
)
expect
(
diff_file
).
to
be_binary
expect
(
diff_file
.
diff
).
to
eq
(
mr_diff
.
compare
.
diffs
(
paths:
[
filename
]).
to_a
.
first
.
diff
)
expect
(
diff_file
.
diff
).
to
include
(
content
)
end
end
end
end
end
end
...
...
spec/support/helpers/repo_helpers.rb
View file @
a19c6342
...
@@ -115,4 +115,18 @@ eos
...
@@ -115,4 +115,18 @@ eos
commits:
commits
commits:
commits
)
)
end
end
def
create_file_in_repo
(
project
,
start_branch
,
branch_name
,
filename
,
content
,
commit_message:
'Add new content'
)
Files
::
CreateService
.
new
(
project
,
project
.
owner
,
commit_message:
commit_message
,
start_branch:
start_branch
,
branch_name:
branch_name
,
file_path:
filename
,
file_content:
content
).
execute
end
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