Skip to content

Commit

Permalink
unescape space path name (#415)
Browse files Browse the repository at this point in the history
* unescape space path name

Signed-off-by: Mason Fish <mason@looky.cloud>

* adjust router config instead

Signed-off-by: Mason Fish <mason@looky.cloud>

Co-authored-by: Mason Fish <mason@looky.cloud>
  • Loading branch information
mason-fish and Mason Fish committed Mar 12, 2020
1 parent 6cbd6d2 commit 98b50b0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
17 changes: 17 additions & 0 deletions zqd/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"io/ioutil"
"net/http"
"net/http/httptest"
"net/url"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -182,6 +183,22 @@ func TestSpaceDelete(t *testing.T) {
})
}

func TestURLEncodingSupport(t *testing.T) {
c := newCore(t)
defer os.RemoveAll(c.Root)

rawSpace := "raw %<>space.brim"
encodedSpaceURL := fmt.Sprintf("http://localhost:9867/space/%s", url.PathEscape(rawSpace))

createSpace(t, c, rawSpace, "")

res := httpRequest(t, zqd.NewHandler(c), "GET", encodedSpaceURL, nil)
require.Equal(t, http.StatusOK, res.StatusCode)

res = httpRequest(t, zqd.NewHandler(c), "DELETE", encodedSpaceURL, nil)
require.Equal(t, http.StatusNoContent, res.StatusCode)
}

func TestNoEndSlashSupport(t *testing.T) {
c := newCore(t)
defer os.RemoveAll(c.Root)
Expand Down
1 change: 0 additions & 1 deletion zqd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ var Version VersionMessage

func NewHandler(root *Core) http.Handler {
r := mux.NewRouter()
r = r.UseEncodedPath()
r.Handle("/space", wrapRoot(root, handleSpaceList)).Methods("GET")
r.Handle("/space", wrapRoot(root, handleSpacePost)).Methods("POST")
r.Handle("/space/{space}", wrapRoot(root, handleSpaceGet)).Methods("GET")
Expand Down

0 comments on commit 98b50b0

Please sign in to comment.