diff options
author | Sean McGivern <sean@gitlab.com> | 2016-08-23 16:37:14 +0100 |
---|---|---|
committer | Sean McGivern <sean@gitlab.com> | 2016-08-25 08:27:08 +0100 |
commit | 44eb3197a9c30503a00384b3d688b64558b80397 (patch) | |
tree | 852391adf4834d2ef8cc6a53e173e93c5b533c9b /lib/gitlab/conflict | |
parent | b2bf01f4c271be66e93ed6f4b48a1da4d50e558d (diff) | |
download | gitlab-ce-44eb3197a9c30503a00384b3d688b64558b80397.tar.gz |
Handle non-UTF-8 conflicts gracefully21247-mergerequestscontroller-conflicts-may-fail-with-iso-8859-data
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.
Diffstat (limited to 'lib/gitlab/conflict')
-rw-r--r-- | lib/gitlab/conflict/parser.rb | 9 |
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 |