10000 Added support for index.php in nested directories · symfony-cli/symfony-cli@7b158c8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7b158c8

Browse files
Added support for index.php in nested directories
1 parent 75f91e3 commit 7b158c8

File tree

4 files changed

+98
-1
lines changed

4 files changed

+98
-1
lines changed

local/php/envs.go

Lines changed: 19 additions & 0 deletions
< 10000 td data-grid-cell-id="diff-42e8482592f40fb0b9c385cc3af23280589513bd9ac2a23dd61f94e8bcb78c04-44-63-2" data-line-anchor="diff-42e8482592f40fb0b9c385cc3af23280589513bd9ac2a23dd61f94e8bcb78c04R63" data-selected="false" role="gridcell" style="background-color:var(--diffBlob-additionLine-bgColor, var(--diffBlob-addition-bgColor-line));padding-right:24px" tabindex="-1" valign="top" class="focusable-grid-cell diff-text-cell right-side-diff-cell left-side">+
}
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,36 @@ import (
3131

3232
func (p *Server) generateEnv(req *http.Request) map[string]string {
3333
scriptName := p.passthru
34+
3435
https := ""
3536
if req.TLS != nil {
3637
https = "On"
3738
}
3839

3940
pathInfo := req.URL.Path
41+
filenameMatch := false
42+
4043
if pos := strings.Index(strings.ToLower(pathInfo), ".php"); pos != -1 {
4144
file := pathInfo[:pos+4]
4245
if _, err := os.Stat(filepath.Join(p.documentRoot, file)); err == nil {
4346
scriptName = file
4447
pathInfo = pathInfo[pos+4:]
48+
filenameMatch = true
49+
}
50+
51+
}
52+
53+
if filenameMatch == false && pathInfo != "/" && len(pathInfo) > 0 {
54+
paths := strings.Split(strings.Trim(pathInfo, "/"), "/")
55+
for i, n := 0, len(paths); i < n; i++ {
56+
poppedPath := paths[:len(paths)-i]
57+
indexDir := filepath.Join(poppedPath...)
58+
file := filepath.Join(indexDir, p.passthru)
59+
if _, err := os.Stat(filepath.Join(p.documentRoot, file)); err == nil {
60+
scriptName = string(os.PathSeparator) + file
61+
pathInfo = pathInfo[strings.Index(pathInfo, indexDir)+len(indexDir):]
62+
break
63
4564
}
4665
}
4766

local/php/envs_test.go

Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ type PHPFPMSuite struct{}
3333
var _ = Suite(&PHPFPMSuite{})
3434

3535
func (s *PHPFPMSuite) TestGenerateEnv(c *C) {
36+
3637
testdataDir := "testdata"
3738
tests := []struct {
3839
uri string
@@ -182,6 +183,83 @@ func (s *PHPFPMSuite) TestGenerateEnv(c *C) {
182183
"SCRIPT_NAME": "/index.php",
183184
},
184185
},
186+
{
187+
passthru: "/index.php",
188+
uri: "/subdirectory",
189+
expected: map[string]string{
190+
"PATH_INFO": "",
191+
"REQUEST_URI": "/subdirectory",
192+
"QUERY_STRING": "",
193+
"SCRIPT_FILENAME": testdataDir + "/public/subdirectory/index.php",
194+
"SCRIPT_NAME": "/subdirectory/index.php",
195+
},
196+
},
197+
{
198+
passthru: "/index.php",
199+
uri: "/subdirectory/",
200+
expected: map[string]string{
201+
"PATH_INFO": "/",
202+
"REQUEST_URI": "/subdirectory/",
203+
"QUERY_STRING": "",
204+
"SCRIPT_FILENAME": testdataDir + "/public/subdirectory/index.php",
205+
"SCRIPT_NAME": "/subdirectory/index.php",
206+
},
207+
},
208+
{
209+
passthru: "/index.php",
210+
uri: "/subdirectory/unknown.php",
211+
expected: map[string]string{
212+
"PATH_INFO": "/unknown.php",
213+
"REQUEST_URI": "/subdirectory/unknown.php",
214+
"QUERY_STRING": "",
215+
"SCRIPT_FILENAME": testdataDir + "/public/subdirectory/index.php",
216+
"SCRIPT_NAME": "/subdirectory/index.php",
217+
},
218+
},
219+
{
220+
passthru: "/index.php",
221+
uri: "/subdirectory/unknown.php/",
222+
expected: map[string]string{
223+
"PATH_INFO": "/unknown.php/",
224+
"REQUEST_URI": "/subdirectory/unknown.php/",
225+
"QUERY_STRING": "",
226+
"SCRIPT_FILENAME": testdataDir + "/public/subdirectory/index.php",
227+
"SCRIPT_NAME": "/subdirectory/index.php",
228+
},
229+
},
230+
{
231+
passthru: "/index.php",
232+
uri: "/subdirectory/index.php/foo",
233+
expected: map[string]string{
234+
"PATH_INFO": "/foo",
235+
"REQUEST_URI": "/subdirectory/index.php/foo",
236+
"QUERY_STRING": "",
237+
"SCRIPT_FILENAME": testdataDir + "/public/subdirectory/index.php",
238+
"SCRIPT_NAME": "/subdirectory/index.php",
239+
},
240+
},
241+
{
242+
passthru: "/index.php",
243+
uri: "/subdirectory/subdirectory/",
244+
expected: map[string]string{
245+
"PATH_INFO": "/",
246+
"REQUEST_URI": "/subdirectory/subdirectory/",
247+
"QUERY_STRING": "",
248+
"SCRIPT_FILENAME": testdataDir + "/public/subdirectory/subdirectory/index.php",
249+
"SCRIPT_NAME": "/subdirectory/subdirectory/index.php",
250+
},
251+
},
252+
{
253+
passthru: "/index.php",
254+
uri: "///subdirectory",
255+
expected: map[string]string{
256+
"PATH_INFO": "",
257+
"REQUEST_URI": "///subdirectory",
258+
"QUERY_STRING": "",
259+
"SCRIPT_FILENAME": testdataDir + "/public/subdirectory/index.php",
260+
"SCRIPT_NAME": "/subdirectory/index.php",
261+
},
262+
},
185263
}
186264
for _, test := range tests {
187265
process := &Server{
@@ -197,7 +275,7 @@ func (s *PHPFPMSuite) TestGenerateEnv(c *C) {
197275
for k, v := range test.expected {
198276
vv, ok := env[k]
199277
c.Assert(ok, Equals, true)
200-
c.Assert(vv, DeepEquals, v)
278+
c.Assert(vv, DeepEquals, v, Commentf("#test uri:\"%s\" varName:\"%s\"", test.uri, k))
201279
}
202280
}
203281
}

local/php/testdata/public/subdirectory/index.php

Whitespace-only changes.

local/php/testdata/public/subdirectory/subdirectory/index.php

Whitespace-only changes.

0 commit comments

Comments
 (0)
0