From f61d4f849e17e09b8919c85307d2850970a3f792 Mon Sep 17 00:00:00 2001 From: matheusgomes28 Date: Mon, 29 Apr 2024 21:44:44 +0100 Subject: [PATCH] fixed the remaing tests * Added the default 500 error when the HTML generator functions error * Fixed some bugs with the string partitioning algorithm --- admin-app/post.go | 9 +++++++++ app/app.go | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/admin-app/post.go b/admin-app/post.go index 3469c3c..7462cb3 100644 --- a/admin-app/post.go +++ b/admin-app/post.go @@ -139,6 +139,10 @@ func deletePostHandler(database database.Database) func(*gin.Context) { // removing the given ranges func partitionString(text string, indexes [][]int) []string { + if len(text) == 0 { + return []string{} + } + partitions := make([]string, 0) start := 0 for _, window := range indexes { @@ -187,10 +191,15 @@ func transformContent(content string, shortcode_handlers map[string]*lua.LState) regex, _ := regexp.Compile(`{{[\w.-]+(:[\w.-]+)+}}`) shortcodes := regex.FindAllStringIndex(content, -1) + if len(shortcodes) == 0 { + return content, nil + } + partitions := partitionString(content, shortcodes) builder := strings.Builder{} i := 0 + for i, shortcode := range shortcodes { builder.WriteString(partitions[i]) diff --git a/app/app.go b/app/app.go index 76cf469..37b3f71 100644 --- a/app/app.go +++ b/app/app.go @@ -57,7 +57,7 @@ func addCachableHandler(e *gin.Engine, method string, endpoint string, generator if err != nil { log.Error().Msgf("could not generate html: %v", err) // TODO : Need a proper error page - // c.JSON(http.StatusInternalServerError, common.ErrorRes("could not render HTML", err)) + c.JSON(http.StatusInternalServerError, common.ErrorRes("could not render HTML", err)) return }