From c7e368ed2eac753baf23ecb25b7aec2e699fb259 Mon Sep 17 00:00:00 2001 From: ekzyis Date: Thu, 31 Aug 2023 09:56:51 +0200 Subject: [PATCH] Fix slice out of bounds error Fixes following error: panic: runtime error: slice bounds out of range [:80] with length 53 --- sn.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sn.go b/sn.go index dd1a3aa..b397ed9 100644 --- a/sn.go +++ b/sn.go @@ -38,7 +38,12 @@ func PostStoryToStackerNews(story *Story, options PostStoryOptions) (int, error) } } - parentId, err := sn.PostLink(url, story.Title[0:80], "tech") + title := story.Title + if len(title) > 80 { + title = title[0:80] + } + + parentId, err := sn.PostLink(url, title, "tech") if err != nil { return -1, fmt.Errorf("error posting link: %w", err) }