github.com/cloudwego/hertz@v0.9.3/pkg/protocol/uri_windows_test.go (about)

     1  // Copyright 2023 CloudWeGo Authors
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  // http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package protocol
    16  
    17  import (
    18  	"testing"
    19  
    20  	"github.com/cloudwego/hertz/pkg/common/test/assert"
    21  )
    22  
    23  func TestURIPathNormalizeIssue86(t *testing.T) {
    24  	t.Parallel()
    25  
    26  	var u URI
    27  
    28  	testURIPathNormalize(t, &u, `a`, `/a`)
    29  	testURIPathNormalize(t, &u, "/../../../../../foo", "/foo")
    30  	testURIPathNormalize(t, &u, "/..\\..\\..\\..\\..\\", "/")
    31  	testURIPathNormalize(t, &u, "/..%5c..%5cfoo", "/foo")
    32  }
    33  
    34  func TestGetScheme(t *testing.T) {
    35  	scheme, path := getScheme([]byte("E:\\file.go"))
    36  	assert.DeepEqual(t, "", string(scheme))
    37  	assert.DeepEqual(t, "E:\\file.go", string(path))
    38  
    39  	scheme, path = getScheme([]byte("E:\\"))
    40  	assert.DeepEqual(t, "", string(scheme))
    41  	assert.DeepEqual(t, "E:\\", string(path))
    42  
    43  	scheme, path = getScheme([]byte("https://foo.com"))
    44  	assert.DeepEqual(t, "https", string(scheme))
    45  	assert.DeepEqual(t, "//foo.com", string(path))
    46  
    47  	scheme, path = getScheme([]byte("://"))
    48  	assert.DeepEqual(t, "", string(scheme))
    49  	assert.DeepEqual(t, "", string(path))
    50  
    51  	scheme, path = getScheme([]byte("ws://127.0.0.1"))
    52  	assert.DeepEqual(t, "ws", string(scheme))
    53  	assert.DeepEqual(t, "//127.0.0.1", string(path))
    54  }