This repository was archived by the owner on Nov 5, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 5 files changed +50
-7
lines changed Expand file tree Collapse file tree 5 files changed +50
-7
lines changed Original file line number Diff line number Diff line change 11package teaconst
22
33const (
4- TeaVersion = "0.1.9.1 "
4+ TeaVersion = "0.1.9.2 "
55
66 TeaProcessName = "teaweb" // 进程名
77 TeaProductName = "TeaWeb" // 产品名
Original file line number Diff line number Diff line change @@ -2,7 +2,6 @@ package teaproxy
22
33import (
44 "net/http"
5- "path/filepath"
65)
76
87// 自定义ServeMux
@@ -12,7 +11,7 @@ type HTTPServeMux struct {
1211
1312func (this * HTTPServeMux ) ServeHTTP (w http.ResponseWriter , r * http.Request ) {
1413 // 解决因为URL中包含多个/而自动跳转的问题
15- r .URL .Path = filepath . Clean (r .URL .Path )
14+ r .URL .Path = CleanPath (r .URL .Path )
1615
1716 this .ServeMux .ServeHTTP (w , r )
1817}
Original file line number Diff line number Diff line change 99 "io"
1010 "net/http"
1111 "net/url"
12- "path/filepath"
1312 "strings"
1413 "time"
1514)
@@ -61,11 +60,10 @@ func (this *Request) callBackend(writer *ResponseWriter) error {
6160
6261 // new uri
6362 if this .backend .HasRequestURI () {
64- uri := filepath .Clean (this .Format (this .backend .RequestPath ()))
65-
63+ uri := this .Format (this .backend .RequestPath ())
6664 u , err := url .ParseRequestURI (uri )
6765 if err == nil {
68- this .raw .URL .Path = u .Path
66+ this .raw .URL .Path = CleanPath ( u .Path )
6967 this .raw .URL .RawQuery = u .RawQuery
7068
7169 args := this .Format (this .backend .RequestArgs ())
Original file line number Diff line number Diff line change 1+ package teaproxy
2+
3+ // 清理Path中的多于信息
4+ func CleanPath (path string ) string {
5+ l := len (path )
6+ if l == 0 {
7+ return "/"
8+ }
9+ result := []byte {'/' }
10+ isSlash := true
11+ for i := 0 ; i < l ; i ++ {
12+ if path [i ] == '\\' || path [i ] == '/' {
13+ if ! isSlash {
14+ isSlash = true
15+ result = append (result , '/' )
16+ }
17+ } else {
18+ isSlash = false
19+ result = append (result , path [i ])
20+ }
21+ }
22+ return string (result )
23+ }
Original file line number Diff line number Diff line change 1+ package teaproxy
2+
3+ import (
4+ "github.com/iwind/TeaGo/assert"
5+ "testing"
6+ )
7+
8+ func TestCleanPath (t * testing.T ) {
9+ a := assert .NewAssertion (t )
10+
11+ a .IsTrue (CleanPath ("" ) == "/" )
12+ a .IsTrue (CleanPath ("/hello/world" ) == "/hello/world" )
13+ a .IsTrue (CleanPath ("\\ hello\\ world" ) == "/hello/world" )
14+ a .IsTrue (CleanPath ("/\\ hello\\ //world" ) == "/hello/world" )
15+ a .IsTrue (CleanPath ("hello/world" ) == "/hello/world" )
16+ a .IsTrue (CleanPath ("/hello////world" ) == "/hello/world" )
17+ }
18+
19+ func BenchmarkCleanPath (b * testing.B ) {
20+ for i := 0 ; i < b .N ; i ++ {
21+ _ = CleanPath ("/hello///world/very/long/very//long" )
22+ }
23+ }
You can’t perform that action at this time.
0 commit comments