Browse Source

Fixed bug with building merge diff for files with different charset

Ivan Arkhipov 6 years ago
parent
commit
cc27ef13c2
1 changed files with 4 additions and 0 deletions
  1. 4 0
      pkg/tool/tool.go

+ 4 - 0
pkg/tool/tool.go

@@ -62,6 +62,10 @@ func DetectEncoding(content []byte) (string, error) {
 	}
 
 	result, err := chardet.NewTextDetector().DetectBest(content)
+	if result == nil || err != nil {
+		return "UTF-8", err
+	}
+
 	if result.Charset != "UTF-8" && len(setting.Repository.AnsiCharset) > 0 {
 		log.Trace("Using default AnsiCharset: %s", setting.Repository.AnsiCharset)
 		return setting.Repository.AnsiCharset, err