Skip to content

Commit e66b0a3

Browse files
committed
test: inline escapePath benchmarks
1 parent 5184fcf commit e66b0a3

File tree

2 files changed

+28
-31
lines changed

2 files changed

+28
-31
lines changed

escape_path_test.go

Lines changed: 0 additions & 31 deletions
This file was deleted.

helpers_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,34 @@ func Benchmark_Utils_SortAcceptedTypes_Unsorted(b *testing.B) {
468468
}, acceptedTypes)
469469
}
470470

471+
func Test_escapePath(t *testing.T) {
472+
t.Parallel()
473+
cases := map[string]string{
474+
"/": "/",
475+
"/foo/bar": "/foo/bar",
476+
"/foo bar": "/foo+bar",
477+
"/does/not/exist<script>alert('foo');</script>": "/does/not/exist%3Cscript%3Ealert%28%27foo%27%29%3B%3C/script%3E",
478+
}
479+
for input, expected := range cases {
480+
require.Equal(t, expected, escapePath(input), input)
481+
}
482+
}
483+
484+
func Benchmark_EscapePath(b *testing.B) {
485+
samples := []string{
486+
"/foo/bar",
487+
"/does/not/exist<script>alert('foo');</script>",
488+
}
489+
for _, sample := range samples {
490+
b.Run(sample, func(b *testing.B) {
491+
b.ReportAllocs()
492+
for b.Loop() {
493+
_ = escapePath(sample)
494+
}
495+
})
496+
}
497+
}
498+
471499
func Test_Utils_UniqueRouteStack(t *testing.T) {
472500
t.Parallel()
473501
route1 := &Route{}

0 commit comments

Comments
 (0)