Skip to content

Commit e104529

Browse files
authored
Merge pull request #137 from tucksaun/fix-135
Rework PATH_INFO computation
2 parents 4bbd1db + 15a9100 commit e104529

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

local/php/envs.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ func (p *Server) generateEnv(req *http.Request) map[string]string {
3636
https = "On"
3737
}
3838

39-
pathInfo := ""
40-
if pos := strings.Index(strings.ToLower(req.RequestURI), ".php"); pos != -1 {
41-
file := req.RequestURI[:pos+4]
39+
pathInfo := req.URL.Path
40+
if pos := strings.Index(strings.ToLower(pathInfo), ".php"); pos != -1 {
41+
file := pathInfo[:pos+4]
4242
if _, err := os.Stat(filepath.Join(p.documentRoot, file)); err == nil {
4343
scriptName = file
44-
pathInfo = req.RequestURI[pos+4:]
44+
pathInfo = pathInfo[pos+4:]
4545
}
4646
}
4747

local/php/envs_test.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,24 @@ func (s *PHPFPMSuite) TestGenerateEnv(c *C) {
4343
passthru: "/index.php",
4444
uri: "/",
4545
expected: map[string]string{
46-
"PATH_INFO": "",
46+
"PATH_INFO": "/",
4747
"REQUEST_URI": "/",
4848
"QUERY_STRING": "",
4949
"SCRIPT_FILENAME": testdataDir + "/public/index.php",
5050
"SCRIPT_NAME": "/index.php",
5151
},
5252
},
53+
{
54+
passthru: "/index.php",
55+
uri: "/?foo=bar",
56+
expected: map[string]string{
57+
"PATH_INFO": "/",
58+
"REQUEST_URI": "/",
59+
"QUERY_STRING": "foo=bar",
60+
"SCRIPT_FILENAME": testdataDir + "/public/index.php",
61+
"SCRIPT_NAME": "/index.php",
62+
},
63+
},
5364
{
5465
passthru: "/index.php",
5566
uri: "/index.php",
@@ -83,6 +94,17 @@ func (s *PHPFPMSuite) TestGenerateEnv(c *C) {
8394
"SCRIPT_NAME": "/app.PHP",
8495
},
8596
},
97+
{
98+
passthru: "/index.php",
99+
uri: "/index.php/foo?foo=bar",
100+
expected: map[string]string{
101+
"PATH_INFO": "/foo",
102+
"REQUEST_URI": "/index.php/foo?foo=bar",
103+
"QUERY_STRING": "foo=bar",
104+
"SCRIPT_FILENAME": testdataDir + "/public/index.php",
105+
"SCRIPT_NAME": "/index.php",
106+
},
107+
},
86108
{
87109
passthru: "/index.php",
88110
uri: "/foo",

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy