BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
0ace54e8
Commit
0ace54e8
authored
Mar 15, 2017
by
Robert Speicher
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'allow-resolving-conflicts-in-utf-8' into 'master'
Allow resolving conflicts with non-ASCII chars Closes #26214 See merge request !9937
parents
6619772f
96c77bf7
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
14 deletions
+45
-14
allow-resolving-conflicts-in-utf-8.yml
changelogs/unreleased/allow-resolving-conflicts-in-utf-8.yml
+4
-0
parser.rb
lib/gitlab/conflict/parser.rb
+3
-5
parser_spec.rb
spec/lib/gitlab/conflict/parser_spec.rb
+38
-9
No files found.
changelogs/unreleased/allow-resolving-conflicts-in-utf-8.yml
0 → 100644
View file @
0ace54e8
---
title
:
Fix conflict resolution when files contain valid UTF-8 characters
merge_request
:
author
:
lib/gitlab/conflict/parser.rb
View file @
0ace54e8
...
...
@@ -15,11 +15,9 @@ module Gitlab
raise
UnmergeableFile
if
text
.
blank?
# Typically a binary file
raise
UnmergeableFile
if
text
.
length
>
200
.
kilobytes
begin
text
.
to_json
rescue
Encoding
::
UndefinedConversionError
raise
UnsupportedEncoding
end
text
.
force_encoding
(
'UTF-8'
)
raise
UnsupportedEncoding
unless
text
.
valid_encoding?
line_obj_index
=
0
line_old
=
1
...
...
spec/lib/gitlab/conflict/parser_spec.rb
View file @
0ace54e8
...
...
@@ -120,44 +120,62 @@ CONFLICT
end
context
'when the file contents include conflict delimiters'
do
it
'raises UnexpectedDelimiter when there is a non-start delimiter first'
do
context
'when there is a non-start delimiter first'
do
it
'raises UnexpectedDelimiter when there is a middle delimiter first'
do
expect
{
parse_text
(
'======='
)
}.
to
raise_error
(
Gitlab
::
Conflict
::
Parser
::
UnexpectedDelimiter
)
end
it
'raises UnexpectedDelimiter when there is an end delimiter first'
do
expect
{
parse_text
(
'>>>>>>> README.md'
)
}.
to
raise_error
(
Gitlab
::
Conflict
::
Parser
::
UnexpectedDelimiter
)
end
it
'does not raise when there is an end delimiter for a different path first'
do
expect
{
parse_text
(
'>>>>>>> some-other-path.md'
)
}.
not_to
raise_error
end
end
it
'raises UnexpectedDelimiter
when a start delimiter is followed by a non-middle delimiter'
do
start_text
=
"<<<<<<< README.md
\n
"
end_text
=
"
\n
=======
\n
>>>>>>> README.md"
context
'
when a start delimiter is followed by a non-middle delimiter'
do
let
(
:start_text
)
{
"<<<<<<< README.md
\n
"
}
let
(
:end_text
)
{
"
\n
=======
\n
>>>>>>> README.md"
}
it
'raises UnexpectedDelimiter when it is followed by an end delimiter'
do
expect
{
parse_text
(
start_text
+
'>>>>>>> README.md'
+
end_text
)
}.
to
raise_error
(
Gitlab
::
Conflict
::
Parser
::
UnexpectedDelimiter
)
end
it
'raises UnexpectedDelimiter when it is followed by another start delimiter'
do
expect
{
parse_text
(
start_text
+
start_text
+
end_text
)
}.
to
raise_error
(
Gitlab
::
Conflict
::
Parser
::
UnexpectedDelimiter
)
end
it
'does not raise when it is followed by a start delimiter for a different path'
do
expect
{
parse_text
(
start_text
+
'>>>>>>> some-other-path.md'
+
end_text
)
}.
not_to
raise_error
end
end
it
'raises UnexpectedDelimiter
when a middle delimiter is followed by a non-end delimiter'
do
start_text
=
"<<<<<<< README.md
\n
=======
\n
"
end_text
=
"
\n
>>>>>>> README.md"
context
'
when a middle delimiter is followed by a non-end delimiter'
do
let
(
:start_text
)
{
"<<<<<<< README.md
\n
=======
\n
"
}
let
(
:end_text
)
{
"
\n
>>>>>>> README.md"
}
it
'raises UnexpectedDelimiter when it is followed by another middle delimiter'
do
expect
{
parse_text
(
start_text
+
'======='
+
end_text
)
}.
to
raise_error
(
Gitlab
::
Conflict
::
Parser
::
UnexpectedDelimiter
)
end
it
'raises UnexpectedDelimiter when it is followed by a start delimiter'
do
expect
{
parse_text
(
start_text
+
start_text
+
end_text
)
}.
to
raise_error
(
Gitlab
::
Conflict
::
Parser
::
UnexpectedDelimiter
)
end
expect
{
parse_text
(
start_text
+
'>>>>>>> some-other-path.md'
+
end_text
)
}.
it
'does not raise when it is followed by a start delimiter for another path'
do
expect
{
parse_text
(
start_text
+
'<<<<<<< some-other-path.md'
+
end_text
)
}.
not_to
raise_error
end
end
it
'raises MissingEndDelimiter when there is no end delimiter at the end'
do
start_text
=
"<<<<<<< README.md
\n
=======
\n
"
...
...
@@ -184,10 +202,21 @@ CONFLICT
to
raise_error
(
Gitlab
::
Conflict
::
Parser
::
UnmergeableFile
)
end
it
'raises UnsupportedEncoding when the file contains non-UTF-8 characters'
do
# All text from Rugged has an encoding of ASCII_8BIT, so force that in
# these strings.
context
'when the file contains UTF-8 characters'
do
it
'does not raise'
do
expect
{
parse_text
(
"Espa
\xC3\xB1
a"
.
force_encoding
(
Encoding
::
ASCII_8BIT
))
}.
not_to
raise_error
end
end
context
'when the file contains non-UTF-8 characters'
do
it
'raises UnsupportedEncoding'
do
expect
{
parse_text
(
"a
\xC4\xFC
"
.
force_encoding
(
Encoding
::
ASCII_8BIT
))
}.
to
raise_error
(
Gitlab
::
Conflict
::
Parser
::
UnsupportedEncoding
)
end
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