@ -22,8 +22,7 @@ import (
"github.com/caddyserver/caddy/v2/modules/caddyhttp"
"github.com/caddyserver/caddy/v2/modules/caddyhttp"
)
)
func TestPhpFileMatcher ( t * testing . T ) {
func TestPHPFileMatcher ( t * testing . T ) {
for i , tc := range [ ] struct {
for i , tc := range [ ] struct {
path string
path string
expectedPath string
expectedPath string
@ -72,19 +71,35 @@ func TestPhpFileMatcher(t *testing.T) {
expectedPath : "/foo.php.php/index.php" ,
expectedPath : "/foo.php.php/index.php" ,
matched : true ,
matched : true ,
} ,
} ,
{
path : "/foo.php.PHP/index.php" ,
expectedPath : "/foo.php.PHP/index.php" ,
matched : true ,
} ,
{
// See https://github.com/caddyserver/caddy/issues/3623
path : "/%E2%C3" ,
expectedPath : "/%E2%C3" ,
matched : false ,
} ,
} {
} {
m := & MatchFile {
m := & MatchFile {
Root : "./testdata" ,
Root : "./testdata" ,
TryFiles : [ ] string { "{http.request.uri.path}" } ,
TryFiles : [ ] string { "{http.request.uri.path}" , "{http.request.uri.path}/index.php" } ,
SplitPath : [ ] string { ".php" } ,
SplitPath : [ ] string { ".php" } ,
}
}
req := & http . Request { URL : & url . URL { Path : tc . path } }
u , err := url . Parse ( tc . path )
if err != nil {
t . Fatalf ( "Test %d: parsing path: %v" , i , err )
}
req := & http . Request { URL : u }
repl := caddyhttp . NewTestReplacer ( req )
repl := caddyhttp . NewTestReplacer ( req )
result := m . Match ( req )
result := m . Match ( req )
if result != tc . matched {
if result != tc . matched {
t . Fatalf ( "Test %d: match bool result: %v, expected: %v" , i , result , tc . matched )
t . Fatalf ( "Test %d: expected match=%t, got %t " , i , tc . matched , result )
}
}
rel , ok := repl . Get ( "http.matchers.file.relative" )
rel , ok := repl . Get ( "http.matchers.file.relative" )