10000 Rework PATH_INFO computation · symfony-cli/symfony-cli@15a9100 · GitHub
[go: up one dir, main page]

Skip to content

Commit 15a9100

Browse files
committed
Rework PATH_INFO computation
Before we were adding PATH_INFO only when `.php` was detected in the URI. Now we always provide the PATH_INFO based on what the Go web server parsed (which excludes the query string) and if we detect `.php` we only provide the trailing bit after. This will remove any query string from PATH_INFO (fix #135), and will also always provide a PATH_INFO even if the script name is not within the URI.
1 parent 672a739 commit 15a9100

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
6FCD
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)
0