8000 Merge pull request #1 from tucksaun/feature/add-index-in-subdirectories · symfony-cli/symfony-cli@c8aa21f · GitHub
[go: up one dir, main page]

Skip to content

Commit c8aa21f

Browse files
Merge pull request #1 from tucksaun/feature/add-index-in-subdirectories
Tweak PHP script name resolution for edge cases
2 parents 93cb65a + f21556a commit c8aa21f

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

local/php/envs.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,24 @@ import (
2929
"github.com/symfony-cli/symfony-cli/envs"
3030
)
3131

32-
func (p *Server) resolveIndexFile(pathInfo string) (string, string) {
33-
32+
func (p *Server) resolveScriptName(pathInfo string) (string, string) {
3433
if pos := strings.Index(strings.ToLower(pathInfo), ".php"); pos != -1 {
3534
file := pathInfo[:pos+4]
3635
if _, err := os.Stat(filepath.Join(p.documentRoot, file)); err == nil {
3736
return file, pathInfo[pos+4:]
3837
}
39-
4038
}
4139

4240
if len(pathInfo) > 1 {
4341
paths := strings.Split(strings.Trim(pathInfo, "/"), "/")
4442
for n := len(paths); n > 0; n-- {
45-
indexDir := filepath.Join(paths[:n]...)
46-
file := filepath.Join(indexDir, p.passthru)
43+
if paths[n-1] == "" {
44+
continue
45+
}
46+
47+
file := filepath.Join(append(paths[:n], p.passthru)...)
4748
if _, err := os.Stat(filepath.Join(p.documentRoot, file)); err == nil {
48-
return "/" + file, pathInfo[strings.Index(pathInfo, indexDir)+len(indexDir):]
49+
return "/" + file, pathInfo[strings.LastIndex(pathInfo, paths[n-1])+len(paths[n-1]):]
4950
}
5051
}
5152
}
@@ -54,8 +55,7 @@ func (p *Server) resolveIndexFile(pathInfo string) (string, string) {
5455
}
5556

5657
func (p *Server) generateEnv(req *http.Request) map[string]string {
57-
58-
scriptName, pathInfo := p.resolveIndexFile(req.URL.Path)
58+
scriptName, pathInfo := p.resolveScriptName(req.URL.Path)
5959

6060
https := ""
6161
if req.TLS != nil {

local/php/envs_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,17 @@ func (s *PHPFPMSuite) TestGenerateEnv(c *C) {
260260
"SCRIPT_NAME": "/subdirectory/index.php",
261261
},
262262
},
263+
{
264+
passthru: "/index.php",
265+
uri: "/subdirectory///subdirectory//foo/",
266+
expected: map[string]string{
267+
"PATH_INFO": "//foo/",
268+
"REQUEST_URI": "/subdirectory///subdirectory//foo/",
269+
"QUERY_STRING": "",
270+
"SCRIPT_FILENAME": testdataDir + "/public/subdirectory/subdirectory/index.php",
271+
"SCRIPT_NAME": "/subdirectory/subdirectory/index.php",
272+
},
273+
},
263274
}
264275
for _, test := range tests {
265276
process := &Server{

0< 31B8 !-- --> commit comments

Comments
 (0)
0