Skip to content

Commit f8bb474

Browse files
arnaldurdaveshanley
authored andcommitted
Use escaped path for StripRequestPath
1 parent aec9928 commit f8bb474

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

paths/paths.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ func StripRequestPath(request *http.Request, document *v3.Document) string {
153153
basePaths := getBasePaths(document)
154154

155155
// strip any base path
156-
stripped := stripBaseFromPath(request.URL.Path, basePaths)
156+
stripped := stripBaseFromPath(request.URL.EscapedPath(), basePaths)
157157
if request.URL.Fragment != "" {
158158
stripped = fmt.Sprintf("%s#%s", stripped, request.URL.Fragment)
159159
}

paths/paths_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,3 +675,24 @@ paths:
675675

676676
assert.Equal(t, expectedPaths, basePaths)
677677
}
678+
679+
func TestNewValidator_FindPathWithEncodedArg(t *testing.T) {
680+
681+
spec := `openapi: 3.1.0
682+
paths:
683+
/something/{string_contains_encoded}:
684+
put:
685+
operationId: putSomething
686+
`
687+
688+
doc, _ := libopenapi.NewDocument([]byte(spec))
689+
690+
m, _ := doc.BuildV3Model()
691+
692+
request, _ := http.NewRequest(http.MethodPut, "https://things.com/something/pkg%3Agithub%2Frs%2Fzerolog%40v1.18.0", nil)
693+
694+
pathItem, errs, _ := FindPath(request, &m.Model)
695+
696+
assert.Equal(t, 0, len(errs), "Errors found: %v", errs)
697+
assert.NotNil(t, pathItem)
698+
}

0 commit comments

Comments
 (0)