diff options
-rw-r--r-- | errors.go | 1 | ||||
-rw-r--r-- | validators.go | 9 |
2 files changed, 7 insertions, 3 deletions
@@ -31,4 +31,5 @@ var ( ErrInvalidRewatchValue = errors.New("mg: invalid rewatch value") ErrInvalidRereadValue = errors.New("mg: invalid reread value") ErrEmptySearchString = errors.New("mg: invalid search string (empty string)") + ErrInvalidYear = errors.New("mg: invalid year (not integer)") ) diff --git a/validators.go b/validators.go index 7386c23..dd45014 100644 --- a/validators.go +++ b/validators.go @@ -19,6 +19,7 @@ package mg import ( "strings" + "strconv" "slices" ) @@ -235,8 +236,12 @@ func validateAnimeRankingParams(params *RankingParams) error { func validateSeasonalParams(params *SeasonalParams) error { // check if year is int + _, err := strconv.Atoi(params.Year) + if err != nil { + return ErrInvalidYear + } - err := validateAnimeSeason(params.Season) + err = validateAnimeSeason(params.Season) if err != nil { return err } @@ -302,7 +307,6 @@ func validateMangaSearchParams(params *SearchParams) error { return err } - func validateMangaRankingParams(params *RankingParams) error { err := validateMangaRankingType(params.RankingType) if err != nil { @@ -318,7 +322,6 @@ func validateMangaRankingParams(params *RankingParams) error { return err } - func validateMangaListParams(params *ListParams) error { // if username is empty, set it to @me if strings.TrimSpace(params.Username) == "" { |