Skip to content

Commit

Permalink
Merge pull request #5 from aschenmaker/fix-delete-bug
Browse files Browse the repository at this point in the history
fix: add check for shortID
  • Loading branch information
krokite authored Dec 2, 2024
2 parents 4a7ea67 + ebf07bf commit 9dd9c43
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,17 @@ func DeleteHandler(bdb *badger.DB, db *pogreb.DB) fiber.Handler {
if err != nil {
return c.JSON(fiber.Map{"error": "true", "message": helper.ErrorPrint(err.Error(), helper.ID107)})
}
// check the shortID, avoid delete wrong link.
if len(post.ShortID) > helper.ShortIDToken {
code := strings.Replace(post.ShortID, "%7C", "|", -1)
val, err := helper.FindDB([]byte(code), db)
if err != nil {
return c.JSON(fiber.Map{"error": "true", "message": helper.ErrorPrint(err.Error(), helper.ID107)})
}
if val != post.URL {
return c.JSON(fiber.Map{"error": "true", "message": helper.ErrorPrint(helper.ID107, helper.ID107)})
}
}
// delete short URL
err = db.Delete([]byte(post.ShortID))
if err != nil {
Expand Down

0 comments on commit 9dd9c43

Please sign in to comment.