From 46c89457dc42701e8975524a0e5a3684620a2ca4 Mon Sep 17 00:00:00 2001 From: Lizandro Guarnizo <77708265+lizandrogd@users.noreply.github.com> Date: Thu, 30 Apr 2026 22:38:52 -0500 Subject: [PATCH] fix: validar sintaxis Go template al guardar plantilla + import html/template --- rest/controllers/notificacion_controller.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/rest/controllers/notificacion_controller.go b/rest/controllers/notificacion_controller.go index bfed4fb..825aa0c 100644 --- a/rest/controllers/notificacion_controller.go +++ b/rest/controllers/notificacion_controller.go @@ -1,6 +1,7 @@ package controllers import ( + "html/template" "math" "strconv" @@ -42,6 +43,11 @@ func CreatePlantilla(c *fiber.Ctx) error { if err := c.BodyParser(&m); err != nil { return c.Status(400).JSON(fiber.Map{"error": err.Error()}) } + if m.CuerpoHTML != "" { + if _, err := template.New("validate").Parse(m.CuerpoHTML); err != nil { + return c.Status(400).JSON(fiber.Map{"error": "Sintaxis inválida en el HTML: " + err.Error()}) + } + } if err := models.CreatePlantilla(m); err != nil { return c.Status(500).JSON(fiber.Map{"error": err.Error()}) } @@ -57,6 +63,11 @@ func UpdatePlantilla(c *fiber.Ctx) error { if err := c.BodyParser(&updates); err != nil { return c.Status(400).JSON(fiber.Map{"error": err.Error()}) } + if html, ok := updates["cuerpo_html"].(string); ok && html != "" { + if _, err := template.New("validate").Parse(html); err != nil { + return c.Status(400).JSON(fiber.Map{"error": "Sintaxis inválida en el HTML: " + err.Error()}) + } + } if err := models.UpdatePlantilla(uint(id), updates); err != nil { return c.Status(500).JSON(fiber.Map{"error": err.Error()}) }