Przeglądaj źródła

Fixed bug with building merge diff for files with different charset

Ivan Arkhipov 6 lat temu
rodzic
commit
90a0f190d0
1 zmienionych plików z 7 dodań i 3 usunięć
  1. 7 3
      internal/tool/tool.go

+ 7 - 3
internal/tool/tool.go

@@ -41,9 +41,13 @@ func DetectEncoding(content []byte) (string, error) {
 	}
 
 	result, err := chardet.NewTextDetector().DetectBest(content)
-	if result.Charset != "UTF-8" && len(conf.Repository.ANSICharset) > 0 {
-		log.Trace("Using default ANSICharset: %s", conf.Repository.ANSICharset)
-		return conf.Repository.ANSICharset, err
+	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
 	}
 
 	log.Trace("Detected encoding: %s", result.Charset)