Skip to content

Commit

Permalink
Fix: should unescape url param
Browse files Browse the repository at this point in the history
  • Loading branch information
Kr328 committed Nov 29, 2022
1 parent 86b6a7e commit 88ab119
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package main

import (
"bytes"
_ "embed"
"encoding/json"
"flag"
"io/fs"
"net"
"net/http"
"net/url"
"os"
"os/signal"
"path/filepath"
Expand All @@ -25,9 +25,6 @@ var (
servePath = flag.String("p", ".", "Local server root path")
)

//go:embed userscript.js
var userscript []byte

func main() {
flag.Parse()

Expand Down Expand Up @@ -100,7 +97,12 @@ func main() {
_, _ = writer.Write(bytes.ReplaceAll(userscript, []byte("%%%SERVER_URL%%%"), []byte("http://"+*listenAt)))
})
r.HandleFunc("/{fileName}", func(writer http.ResponseWriter, request *http.Request) {
fileName := chi.URLParam(request, "fileName")
fileName, err := url.QueryUnescape(chi.URLParam(request, "fileName"))
if err != nil {
writer.WriteHeader(http.StatusBadRequest)

return
}

if strings.Contains(fileName, "/") {
writer.WriteHeader(http.StatusBadRequest)
Expand Down

0 comments on commit 88ab119

Please sign in to comment.