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
Léo-Paul Géneau
gitlab-ce
Commits
18398152
Commit
18398152
authored
Jul 29, 2016
by
Sean McGivern
Committed by
Fatih Acet
Aug 12, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Raise errors for large and binary files
parent
f2f84469
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
10 deletions
+22
-10
lib/gitlab/conflict/parser.rb
lib/gitlab/conflict/parser.rb
+5
-1
spec/lib/gitlab/conflict/parser_spec.rb
spec/lib/gitlab/conflict/parser_spec.rb
+17
-9
No files found.
lib/gitlab/conflict/parser.rb
View file @
18398152
...
...
@@ -10,8 +10,12 @@ module Gitlab
class
MissingEndDelimiter
<
ParserError
end
class
UnmergeableFile
<
ParserError
end
def
parse
(
text
,
our_path
:,
their_path
:,
parent:
nil
)
return
[]
if
text
.
blank?
raise
UnmergeableFile
if
text
.
blank?
# Typically a binary file
raise
UnmergeableFile
if
text
.
length
>
102400
line_obj_index
=
0
line_old
=
1
...
...
spec/lib/gitlab/conflict/parser_spec.rb
View file @
18398152
...
...
@@ -4,6 +4,10 @@ describe Gitlab::Conflict::Parser, lib: true do
let
(
:parser
)
{
Gitlab
::
Conflict
::
Parser
.
new
}
describe
'#parse'
do
def
parse_text
(
text
)
parser
.
parse
(
text
,
our_path:
'README.md'
,
their_path:
'README.md'
)
end
context
'when the file has valid conflicts'
do
let
(
:text
)
do
<<
CONFLICT
...
...
@@ -116,12 +120,6 @@ CONFLICT
end
context
'when the file contents include conflict delimiters'
do
let
(
:path
)
{
'README.md'
}
def
parse_text
(
text
)
parser
.
parse
(
text
,
our_path:
path
,
their_path:
path
)
end
it
'raises UnexpectedDelimiter when there is a non-start delimiter first'
do
expect
{
parse_text
(
'======='
)
}.
to
raise_error
(
Gitlab
::
Conflict
::
Parser
::
UnexpectedDelimiter
)
...
...
@@ -172,9 +170,19 @@ CONFLICT
end
end
context
'when lines is blank'
do
it
{
expect
(
parser
.
parse
(
''
,
our_path:
'README.md'
,
their_path:
'README.md'
)).
to
eq
([])
}
it
{
expect
(
parser
.
parse
(
nil
,
our_path:
'README.md'
,
their_path:
'README.md'
)).
to
eq
([])
}
context
'other file types'
do
it
'raises UnmergeableFile when lines is blank, indicating a binary file'
do
expect
{
parse_text
(
''
)
}.
to
raise_error
(
Gitlab
::
Conflict
::
Parser
::
UnmergeableFile
)
expect
{
parse_text
(
nil
)
}.
to
raise_error
(
Gitlab
::
Conflict
::
Parser
::
UnmergeableFile
)
end
it
'raises UnmergeableFile when the file is over 100 KB'
do
expect
{
parse_text
(
'a'
*
102401
)
}.
to
raise_error
(
Gitlab
::
Conflict
::
Parser
::
UnmergeableFile
)
end
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