Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix: handle urls with multiple slashes#16527

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
mtojek merged 6 commits intomainfrom9877-fix
Feb 12, 2025
Merged
Changes from1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
unit tests
  • Loading branch information
@mtojek
mtojek committedFeb 11, 2025
commit2aef54d9a2e128e145b08b92ba7c7fd986356ef6
47 changes: 47 additions & 0 deletionscoderd/coderd_internal_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
package coderd

import (
"net/http"
"net/http/httptest"
"testing"
)

func TestStripSlashesMW(t *testing.T) {
t.Parallel()

tests := []struct {
name string
inputPath string
wantPath string
}{
{"No changes", "/api/v1/buildinfo", "/api/v1/buildinfo"},
{"Single trailing slash", "/api/v2/buildinfo/", "/api/v2/buildinfo"},
{"Double slashes", "/api//v2//buildinfo", "/api/v2/buildinfo"},
{"Triple slashes", "/api///v2///buildinfo///", "/api/v2/buildinfo"},
{"Leading slashes", "///api/v2/buildinfo", "/api/v2/buildinfo"},
{"Root path", "/", "/"},
{"Double slashes root", "//", "/"},
{"Only slashes", "/////", "/"},
}

handler := http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusOK)
})

for _, tt := range tests {
tt := tt

t.Run(tt.name, func(t *testing.T) {
t.Parallel()

req := httptest.NewRequest("GET", tt.inputPath, nil)
rec := httptest.NewRecorder()

stripSlashesMW(handler).ServeHTTP(rec, req)

if req.URL.Path != tt.wantPath {
t.Errorf("stripSlashesMW got path = %q, want %q", req.URL.Path, tt.wantPath)
}
})
}
}
Loading

[8]ページ先頭

©2009-2025 Movatter.jp