github.com/gramework/gramework@v1.8.1-0.20231027140105-82555c9057f5/fasthttprouter_path_test.go (about)

     1  // Copyright 2013 Julien Schmidt. All rights reserved.
     2  // Copyright (c) 2015-2016, 招牌疯子
     3  // Copyright (c) 2017, Kirill Danshin
     4  // Use of this source code is governed by a BSD-style license that can be found
     5  // in the 3rd-Party License/fasthttprouter file.
     6  
     7  package gramework
     8  
     9  import "testing"
    10  
    11  func TestCleanPath(t *testing.T) {
    12  	if res := CleanPath(""); res != "/" {
    13  		t.Errorf("expected: / actual: %s", res)
    14  	}
    15  
    16  	if res := CleanPath("/hello/../world"); res != "/world" {
    17  		t.Errorf("expected: /world actual: %s", res)
    18  	}
    19  	if res := CleanPath("/hello/../../world"); res != "/world" {
    20  		t.Errorf("expected: /world actual: %s", res)
    21  	}
    22  	if res := CleanPath("hello"); res != "/hello" {
    23  		t.Errorf("expected: /hello actual: %s", res)
    24  	}
    25  	if res := CleanPath("hello/world"); res != "/hello/world" {
    26  		t.Errorf("expected: /hello/world actual: %s", res)
    27  	}
    28  	if res := CleanPath("./hello/world"); res != "/hello/world" {
    29  		t.Errorf("expected: /hello/world actual: %s", res)
    30  	}
    31  	if res := CleanPath("./hello/////world"); res != "/hello/world" {
    32  		t.Errorf("expected: /hello/world actual: %s", res)
    33  	}
    34  	if res := CleanPath("./HeLLo/////world"); res != "/HeLLo/world" {
    35  		t.Errorf("expected: /hello/world actual: %s", res)
    36  	}
    37  	if res := CleanPath("./hello/////world///abс//"); res != "/hello/world/abс/" {
    38  		t.Errorf("expected: /hello/world/abc/ actual: %s", res)
    39  	}
    40  	if res := CleanPath("./hello/////world//../abс//"); res != "/hello/abс/" {
    41  		t.Errorf("expected: /hello/abc/ actual: %s", res)
    42  	}
    43  }