Commit ef28cab3 authored by Stan Hu's avatar Stan Hu Committed by Mayra Cabrera
Browse files

Merge branch...

Merge branch '44564-error-500-while-attempting-to-resolve-conflicts-due-to-utf-8-conversion-error' into 'master'

Resolve "Error 500 while attempting to resolve conflicts due to UTF-8 conversion error"

Closes #44564

See merge request gitlab-org/gitlab-ce!17962
parent cc10d606
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
---
title: Fix 500 error when trying to resolve non-ASCII conflicts in the editor
merge_request: 17962
author:
type: fixed
+4 −1
Original line number Diff line number Diff line
@@ -40,7 +40,10 @@ def can_be_resolved_in_ui?
        # 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?
+13 −3
Original line number Diff line number Diff line
@@ -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 @@ def lines
          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

+0 −5
Original line number Diff line number Diff line
@@ -4,7 +4,6 @@ module Conflict
      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 @@ def parse(text, our_path:, their_path:, parent_file: nil)
          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)
+1 −1
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@ def each

              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
Loading