summaryrefslogtreecommitdiff
path: root/lib/gitlab
diff options
context:
space:
mode:
authorSean McGivern <sean@gitlab.com>2018-03-23 15:02:05 +0000
committerSean McGivern <sean@gitlab.com>2018-03-23 18:33:14 +0000
commit70af1e2e03c031105117596e398f82dee4ae61a4 (patch)
treec679a2c4377fdb7b06ba59745673ba30ac63f603 /lib/gitlab
parentb06a44c4ea85b813c0e6497ad801c3367abbf973 (diff)
downloadgitlab-ce-70af1e2e03c031105117596e398f82dee4ae61a4.tar.gz
Fix 500 error when trying to resolve non-ASCII conflicts in editor
When we added caching, this meant that calling `can_be_resolved_in_ui?` didn't always call `lines`, which meant that we didn't get the benefit of the side-effect from that, where it forced the conflict data itself to UTF-8. To fix that, make this explicit by separating the `raw_content` (any encoding) from the `content` (which is either UTF-8, or an exception is raised).
Diffstat (limited to 'lib/gitlab')
-rw-r--r--lib/gitlab/conflict/file_collection.rb5
-rw-r--r--lib/gitlab/git/conflict/file.rb16
-rw-r--r--lib/gitlab/git/conflict/parser.rb5
-rw-r--r--lib/gitlab/gitaly_client/conflict_files_stitcher.rb2
4 files changed, 18 insertions, 10 deletions
diff --git a/lib/gitlab/conflict/file_collection.rb b/lib/gitlab/conflict/file_collection.rb
index 3ccfd9a739d..65a65b67975 100644
--- a/lib/gitlab/conflict/file_collection.rb
+++ b/lib/gitlab/conflict/file_collection.rb
@@ -40,7 +40,10 @@ module Gitlab
# when there are no conflict files.
files.each(&:lines)
files.any?
- rescue Gitlab::Git::CommandError, Gitlab::Git::Conflict::Parser::UnresolvableError, Gitlab::Git::Conflict::Resolver::ConflictSideMissing
+ rescue Gitlab::Git::CommandError,
+ Gitlab::Git::Conflict::Parser::UnresolvableError,
+ Gitlab::Git::Conflict::Resolver::ConflictSideMissing,
+ Gitlab::Git::Conflict::File::UnsupportedEncoding
false
end
cache_method :can_be_resolved_in_ui?
diff --git a/lib/gitlab/git/conflict/file.rb b/lib/gitlab/git/conflict/file.rb
index 2a9cf10a068..f08dab59ce4 100644
--- a/lib/gitlab/git/conflict/file.rb
+++ b/lib/gitlab/git/conflict/file.rb
@@ -2,17 +2,19 @@ module Gitlab
module Git
module Conflict
class File
+ UnsupportedEncoding = Class.new(StandardError)
+
attr_reader :their_path, :our_path, :our_mode, :repository, :commit_oid
- attr_accessor :content
+ attr_accessor :raw_content
- def initialize(repository, commit_oid, conflict, content)
+ def initialize(repository, commit_oid, conflict, raw_content)
@repository = repository
@commit_oid = commit_oid
@their_path = conflict[:theirs][:path]
@our_path = conflict[:ours][:path]
@our_mode = conflict[:ours][:mode]
- @content = content
+ @raw_content = raw_content
end
def lines
@@ -29,6 +31,14 @@ module Gitlab
end
end
+ def content
+ @content ||= @raw_content.dup.force_encoding('UTF-8')
+
+ raise UnsupportedEncoding unless @content.valid_encoding?
+
+ @content
+ end
+
def type
lines unless @type
diff --git a/lib/gitlab/git/conflict/parser.rb b/lib/gitlab/git/conflict/parser.rb
index 3effa9d2d31..fb5717dd556 100644
--- a/lib/gitlab/git/conflict/parser.rb
+++ b/lib/gitlab/git/conflict/parser.rb
@@ -4,7 +4,6 @@ module Gitlab
class Parser
UnresolvableError = Class.new(StandardError)
UnmergeableFile = Class.new(UnresolvableError)
- UnsupportedEncoding = Class.new(UnresolvableError)
# Recoverable errors - the conflict can be resolved in an editor, but not with
# sections.
@@ -75,10 +74,6 @@ module Gitlab
def validate_text!(text)
raise UnmergeableFile if text.blank? # Typically a binary file
raise UnmergeableFile if text.length > 200.kilobytes
-
- text.force_encoding('UTF-8')
-
- raise UnsupportedEncoding unless text.valid_encoding?
end
def validate_delimiter!(condition)
diff --git a/lib/gitlab/gitaly_client/conflict_files_stitcher.rb b/lib/gitlab/gitaly_client/conflict_files_stitcher.rb
index 97c13d1fdb0..c275a065bce 100644
--- a/lib/gitlab/gitaly_client/conflict_files_stitcher.rb
+++ b/lib/gitlab/gitaly_client/conflict_files_stitcher.rb
@@ -17,7 +17,7 @@ module Gitlab
current_file = file_from_gitaly_header(gitaly_file.header)
else
- current_file.content << gitaly_file.content
+ current_file.raw_content << gitaly_file.content
end
end
end