From 5cd46fd7a6e940e62787b341ae1d05f2d7fe24cd Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Fri, 4 Apr 2025 17:45:06 +0800 Subject: [PATCH] :bug: Fix a NPE in OCR --- kernel/util/ocr.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/kernel/util/ocr.go b/kernel/util/ocr.go index 4a75a7c2a..f4fc44a7d 100644 --- a/kernel/util/ocr.go +++ b/kernel/util/ocr.go @@ -242,8 +242,13 @@ func Tesseract(imgAbsPath string) (ret []map[string]interface{}) { fields := strings.Split(line, "\t") // 将字段名和字段值映射到一个 map 中 dataMap := make(map[string]interface{}) - for i, header := range strings.Split(lines[0], "\t") { - dataMap[header] = fields[i] + headers := strings.Split(lines[0], "\t") + for i, header := range headers { + if i < len(fields) { + dataMap[header] = fields[i] + } else { + dataMap[header] = "" + } } ret = append(ret, dataMap) }