summaryrefslogtreecommitdiff
path: root/lib/gitlab/conflict
diff options
context:
space:
mode:
authorRobert Speicher <robert@gitlab.com>2016-08-25 19:08:38 +0000
committerRobert Speicher <robert@gitlab.com>2016-08-25 19:08:38 +0000
commit75ed0e27d95dcdb6dcc970f25a77e1bd0a63b78f (patch)
tree520855607987139f7b977d4fb9312e315b1f332f /lib/gitlab/conflict
parent2933f3f5975c0176262998cca38b0a3e7ca3c114 (diff)
parent44eb3197a9c30503a00384b3d688b64558b80397 (diff)
downloadgitlab-ce-75ed0e27d95dcdb6dcc970f25a77e1bd0a63b78f.tar.gz
Merge branch '21247-mergerequestscontroller-conflicts-may-fail-with-iso-8859-data' into 'master'
Handle non-UTF-8 conflicts gracefully ## What does this MR do? If a conflict file isn't in a UTF-8-compatible encoding, we can't resolve it in the UI. ## What are the relevant issue numbers? Closes #21247. See merge request !5961
Diffstat (limited to 'lib/gitlab/conflict')
-rw-r--r--lib/gitlab/conflict/parser.rb9
1 files changed, 9 insertions, 0 deletions
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