Skip to content

Commit 05e75a5

Browse files
authored
Parse url path to extract query parameters from filename when calling embed.FS (#103)
* add oauth redirect test case * fix: parse url path to exclude query params from filename
1 parent 1bc40aa commit 05e75a5

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

swagger.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package httpSwagger
33
import (
44
"html/template"
55
"net/http"
6+
"net/url"
67
"path/filepath"
78
"regexp"
89

@@ -213,7 +214,13 @@ func Handler(configFns ...func(*Config)) http.HandlerFunc {
213214
case "":
214215
http.Redirect(w, r, matches[1]+"/"+"index.html", http.StatusMovedPermanently)
215216
default:
216-
r.URL.Path = matches[2]
217+
var err error
218+
r.URL, err = url.Parse(matches[2])
219+
if err != nil {
220+
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
221+
222+
return
223+
}
217224
http.FileServer(http.FS(swaggerFiles.FS)).ServeHTTP(w, r)
218225
}
219226
}

swagger_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ func TestWrapHandler(t *testing.T) {
9696
assert.Equal(t, http.StatusOK, w5.Code)
9797
assert.Equal(t, w5.Header()["Content-Type"][0], "application/javascript")
9898

99+
w6 := performRequest(http.MethodGet, test.RootFolder+"oauth2-redirect.html?state=0&session_state=1&code=2", router)
100+
assert.Equal(t, http.StatusOK, w6.Code)
101+
assert.Equal(t, w6.Header()["Content-Type"][0], "text/html; charset=utf-8")
102+
99103
assert.Equal(t, http.StatusNotFound, performRequest(http.MethodGet, test.RootFolder+"notfound", router).Code)
100104

101105
assert.Equal(t, 301, performRequest(http.MethodGet, test.RootFolder, router).Code)

0 commit comments

Comments
 (0)