fix error with spaces in media name
This commit is contained in:
parent
b60980b368
commit
c24f2cb9db
|
@ -45,3 +45,15 @@ func TestBinaryRepoNoSideEffect(t *testing.T) {
|
||||||
require.Equal(t, file2.Name, "name2")
|
require.Equal(t, file2.Name, "name2")
|
||||||
require.Equal(t, file2.Data, []byte("222"))
|
require.Equal(t, file2.Data, []byte("222"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestBinaryWithSpaceInName(t *testing.T) {
|
||||||
|
repo := setupBinaryRepo()
|
||||||
|
|
||||||
|
file, err := repo.Create("name with space", []byte("111"), nil)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
file, err = repo.FindById(file.Id)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, file.Name, "name with space")
|
||||||
|
require.Equal(t, file.Data, []byte("111"))
|
||||||
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package web
|
package web
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net/url"
|
||||||
"owl-blogs/app"
|
"owl-blogs/app"
|
||||||
|
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
|
@ -16,6 +17,11 @@ func NewMediaHandler(binaryService *app.BinaryService) *MediaHandler {
|
||||||
|
|
||||||
func (h *MediaHandler) Handle(c *fiber.Ctx) error {
|
func (h *MediaHandler) Handle(c *fiber.Ctx) error {
|
||||||
id := c.Params("+")
|
id := c.Params("+")
|
||||||
|
// urldecode
|
||||||
|
id, err := url.PathUnescape(id)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
binary, err := h.binaryService.FindById(id)
|
binary, err := h.binaryService.FindById(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
Loading…
Reference in New Issue