Skip to content

Commit

Permalink
bounds check
Browse files Browse the repository at this point in the history
  • Loading branch information
oklookat committed Feb 15, 2024
1 parent 0d4ce0c commit 184347e
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions text/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package text

import (
"errors"
"fmt"
"strconv"
"strings"
Expand Down Expand Up @@ -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)
Expand All @@ -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])
}

Expand Down

0 comments on commit 184347e

Please # to comment.