From 820e49ec43a25744a0ddc993ad528840b32dba7a Mon Sep 17 00:00:00 2001 From: Matthieu MOREL Date: Thu, 27 Jun 2024 14:50:23 +0200 Subject: [PATCH] Update http_const.go --- internal/checkers/http_const.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/internal/checkers/http_const.go b/internal/checkers/http_const.go index d93335ef..0f91f4a1 100644 --- a/internal/checkers/http_const.go +++ b/internal/checkers/http_const.go @@ -64,7 +64,10 @@ func newHTTPMethodReplacement(e ast.Expr) *analysis.SuggestedFix { if !ok { return nil } - currentVal := unquoteBasicLitValue(bt) + currentVal, ok := unquoteBasicLitValue(bt) + if !ok { + return nil + } key := strings.ToUpper(currentVal) newVal, ok := httpMethod[key] if !ok { @@ -123,7 +126,10 @@ func newAnalysisDiagnostic( } } -func unquoteBasicLitValue(basicLit *ast.BasicLit) string { - s, _ := strconv.Unquote(basicLit.Value) - return s +func unquoteBasicLitValue(basicLit *ast.BasicLit) (string, bool) { + value, err := strconv.Unquote(basicLit.Value) + if err != nil { + return "", false + } + return value, true }