summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean McGivern <sean@gitlab.com>2016-08-23 16:37:14 +0100
committerSean McGivern <sean@gitlab.com>2016-08-25 08:27:08 +0100
commit44eb3197a9c30503a00384b3d688b64558b80397 (patch)
tree852391adf4834d2ef8cc6a53e173e93c5b533c9b
parentb2bf01f4c271be66e93ed6f4b48a1da4d50e558d (diff)
downloadgitlab-ce-44eb3197a9c30503a00384b3d688b64558b80397.tar.gz
These can't be resolved in the UI because if they aren't in a UTF-8 compatible encoding, they can't be rendered as JSON. Even if they could, we would be implicitly changing the file encoding anyway, which seems like a bad idea.
-rw-r--r--CHANGELOG3
-rw-r--r--doc/user/project/merge_requests/resolve_conflicts.md1
-rw-r--r--lib/gitlab/conflict/parser.rb9
-rw-r--r--spec/features/merge_requests/conflicts_spec.rb3
-rw-r--r--spec/lib/gitlab/conflict/parser_spec.rb5
-rw-r--r--spec/support/test_env.rb3
6 files changed, 22 insertions, 2 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 518e80a360a..05517de501a 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -10,6 +10,9 @@ v 8.12.0 (unreleased)
- Added tests for diff notes
- Added 'only_allow_merge_if_build_succeeds' project setting in the API. !5930 (Duck)
+v 8.11.3 (unreleased)
+ - Don't try to show merge conflict resolution info if a merge conflict contains non-UTF-8 characters
+
v 8.11.2 (unreleased)
- Show "Create Merge Request" widget for push events to fork projects on the source project
diff --git a/doc/user/project/merge_requests/resolve_conflicts.md b/doc/user/project/merge_requests/resolve_conflicts.md
index 44b76ffc8e6..4d7225bd820 100644
--- a/doc/user/project/merge_requests/resolve_conflicts.md
+++ b/doc/user/project/merge_requests/resolve_conflicts.md
@@ -26,6 +26,7 @@ this is similar to performing `git checkout feature; git merge master` locally.
GitLab allows resolving conflicts in a file where all of the below are true:
- The file is text, not binary
+- The file is in a UTF-8 compatible encoding
- The file does not already contain conflict markers
- The file, with conflict markers added, is not over 200 KB in size
- The file exists under the same path in both branches
diff --git a/lib/gitlab/conflict/parser.rb b/lib/gitlab/conflict/parser.rb
index 6eccded7872..2d4d55daeeb 100644
--- a/lib/gitlab/conflict/parser.rb
+++ b/lib/gitlab/conflict/parser.rb
@@ -13,10 +13,19 @@ module Gitlab
class UnmergeableFile < ParserError
end
+ class UnsupportedEncoding < ParserError
+ end
+
def parse(text, our_path:, their_path:, parent_file: nil)
raise UnmergeableFile if text.blank? # Typically a binary file
raise UnmergeableFile if text.length > 102400
+ begin
+ text.to_json
+ rescue Encoding::UndefinedConversionError
+ raise UnsupportedEncoding
+ end
+
line_obj_index = 0
line_old = 1
line_new = 1
diff --git a/spec/features/merge_requests/conflicts_spec.rb b/spec/features/merge_requests/conflicts_spec.rb
index 930c36ade2b..759edf8ec80 100644
--- a/spec/features/merge_requests/conflicts_spec.rb
+++ b/spec/features/merge_requests/conflicts_spec.rb
@@ -43,7 +43,8 @@ feature 'Merge request conflict resolution', js: true, feature: true do
'conflict-too-large' => 'when the conflicts contain a large file',
'conflict-binary-file' => 'when the conflicts contain a binary file',
'conflict-contains-conflict-markers' => 'when the conflicts contain a file with ambiguous conflict markers',
- 'conflict-missing-side' => 'when the conflicts contain a file edited in one branch and deleted in another'
+ 'conflict-missing-side' => 'when the conflicts contain a file edited in one branch and deleted in another',
+ 'conflict-non-utf8' => 'when the conflicts contain a non-UTF-8 file',
}
UNRESOLVABLE_CONFLICTS.each do |source_branch, description|
diff --git a/spec/lib/gitlab/conflict/parser_spec.rb b/spec/lib/gitlab/conflict/parser_spec.rb
index 65a828accde..a1d2ca1e272 100644
--- a/spec/lib/gitlab/conflict/parser_spec.rb
+++ b/spec/lib/gitlab/conflict/parser_spec.rb
@@ -183,6 +183,11 @@ CONFLICT
expect { parse_text('a' * 102401) }.
to raise_error(Gitlab::Conflict::Parser::UnmergeableFile)
end
+
+ it 'raises UnsupportedEncoding when the file contains non-UTF-8 characters' do
+ expect { parse_text("a\xC4\xFC".force_encoding(Encoding::ASCII_8BIT)) }.
+ to raise_error(Gitlab::Conflict::Parser::UnsupportedEncoding)
+ end
end
end
end
diff --git a/spec/support/test_env.rb b/spec/support/test_env.rb
index edbbfc3c9e5..c7a45fc4ff9 100644
--- a/spec/support/test_env.rb
+++ b/spec/support/test_env.rb
@@ -24,11 +24,12 @@ module TestEnv
'expand-collapse-lines' => '238e82d',
'video' => '8879059',
'crlf-diff' => '5938907',
- 'conflict-start' => '14fa46b',
+ 'conflict-start' => '75284c7',
'conflict-resolvable' => '1450cd6',
'conflict-binary-file' => '259a6fb',
'conflict-contains-conflict-markers' => '5e0964c',
'conflict-missing-side' => 'eb227b3',
+ 'conflict-non-utf8' => 'd0a293c',
'conflict-too-large' => '39fa04f',
}