From 184347e93ce4151d90bdb076db7ca959fb723a40 Mon Sep 17 00:00:00 2001 From: oklookat Date: Thu, 15 Feb 2024 09:14:39 +0300 Subject: [PATCH] bounds check --- text/main.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/text/main.go b/text/main.go index 2f14c19..74dbcbe 100644 --- a/text/main.go +++ b/text/main.go @@ -1,6 +1,7 @@ package text import ( + "errors" "fmt" "strconv" "strings" @@ -37,6 +38,7 @@ func CleanTitle(title string) (*CleanedTitle, error) { titleName := strings.Join(titleS[:yearInfoCutIdx], " ") yearInfo := titleS[yearInfoCutIdx:] + res, err := parseYear(yearInfo[0]) if err != nil { return nil, fmt.Errorf("%w, %w", errWrongTitle(title), err) @@ -56,6 +58,9 @@ func parseYear(year string) (int, error) { yearS = strings.TrimSuffix(yearS, ")") // [2006, 2010?] yearSP := strings.Split(yearS, "-") + if len(yearSP) == 0 { + return 0, errors.New("parseYear: empty yearSP") + } return strconv.Atoi(yearSP[0]) }