]> granicus.if.org Git - php/commitdiff
Fixed bug #60112 If URI does not contain a file, index.php is not served
authorXinchen Hui <laruence@php.net>
Sun, 23 Oct 2011 02:54:06 +0000 (02:54 +0000)
committerXinchen Hui <laruence@php.net>
Sun, 23 Oct 2011 02:54:06 +0000 (02:54 +0000)
This is a windows Issue.
and after this fix, previously 404 request like "localhost/foo/bar"
now could server correctly with request_uri "index.php" and PATH_INFO "/foo/bar/"

NEWS
sapi/cli/php_cli_server.c

diff --git a/NEWS b/NEWS
index af7f2f559e8f44008cbe7d80576f54ba66f1d83e..916eba0348cfbb1851fef33199eb6fe6f9a795db 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,9 @@ PHP                                                                        NEWS
 ?? ??? 2011, PHP 5.4.0 RC1
 - General improvements:
   . Changed silent conversion of array to string to produce a notice. (Patrick)
+- CLI SAPI:
+  . Fixed bug #60112 (If URI does not contain a file, index.php is not served)
+    .(Laruence)
 
 20 Oct 2011, PHP 5.4.0 beta2
 - General improvements:
index ce792b716c2a000f051ae07a50f61149d38389a0..52e77db8212365c7f8258ca5a159fe92aa8d695e 100644 (file)
@@ -1248,13 +1248,31 @@ static void php_cli_server_request_translate_vpath(php_cli_server_request *reque
        static const char *index_files[] = { "index.php", "index.html", NULL };
        char *buf = safe_pemalloc(1, request->vpath_len, 1 + document_root_len + 1 + sizeof("index.html"), 1);
        char *p = buf, *prev_patch = 0, *q, *vpath;
+       size_t prev_patch_len;
+       int  is_static_file = 0;
+
        memmove(p, document_root, document_root_len);
        p += document_root_len;
        vpath = p;
        if (request->vpath_len > 0 && request->vpath[0] != '/') {
-               *p++ = '/';
+               *p++ = DEFAULT_SLASH;
+       }
+       q = request->vpath + request->vpath_len;
+       while (q > request->vpath) {
+               if (*q-- == '.') {
+                       is_static_file = 1;
+                       break;
+               }
        }
        memmove(p, request->vpath, request->vpath_len);
+#ifdef PHP_WIN32
+       q = p + request->vpath_len;
+       do {
+               if (*q == '/') {
+                       *q = '\\';
+               }
+       } while (q-- > p);
+#endif
        p += request->vpath_len;
        *p = '\0';
        q = p;
@@ -1262,14 +1280,14 @@ static void php_cli_server_request_translate_vpath(php_cli_server_request *reque
                if (!stat(buf, &sb)) {
                        if (sb.st_mode & S_IFDIR) {
                                const char **file = index_files;
-                               if (p > buf && p[-1] != '/') {
-                                       *p++ = '/';
+                               if (q[-1] != DEFAULT_SLASH) {
+                                       *q++ = DEFAULT_SLASH;
                                }
                                while (*file) {
                                        size_t l = strlen(*file);
-                                       memmove(p, *file, l + 1);
+                                       memmove(q, *file, l + 1);
                                        if (!stat(buf, &sb) && (sb.st_mode & S_IFREG)) {
-                                               p += l;
+                                               q += l;
                                                break;
                                        }
                                        file++;
@@ -1280,30 +1298,40 @@ static void php_cli_server_request_translate_vpath(php_cli_server_request *reque
                                }
                        }
                        break; /* regular file */
-               }
-               while (q > buf && *(--q) != '/');
+               } else if (is_static_file) {
+                       pefree(buf, 1);
+                       return;
+               }       
                if (prev_patch) {
-                       *prev_patch = '/';
+                       pefree(prev_patch, 1);
+                       *q = DEFAULT_SLASH;
                }
+               while (q > buf && *(--q) != DEFAULT_SLASH);
+               prev_patch_len = p - q;
+               prev_patch = pestrndup(q, prev_patch_len, 1);
                *q = '\0';
-               prev_patch = q;
        }
        if (prev_patch) {
-               *prev_patch = '/';
-               request->path_info = pestrndup(prev_patch, p - prev_patch, 1);
-               request->path_info_len = p - prev_patch;
+               request->path_info_len = prev_patch_len;
+#ifdef PHP_WIN32
+               while (prev_patch_len--) {
+                       if (prev_patch[prev_patch_len] == '\\') {
+                               prev_patch[prev_patch_len] = '/';
+                       }
+               }
+#endif
+               request->path_info = prev_patch;
                pefree(request->vpath, 1);
-               request->vpath = pestrndup(vpath, prev_patch - vpath, 1);
-               request->vpath_len = prev_patch - vpath;
-               *prev_patch = '\0';
+               request->vpath = pestrndup(vpath, q - vpath, 1);
+               request->vpath_len = q - vpath;
                request->path_translated = buf;
-               request->path_translated_len = prev_patch - buf;
+               request->path_translated_len = q - buf;
        } else {
                pefree(request->vpath, 1);
-               request->vpath = pestrndup(vpath, p - vpath, 1);
-               request->vpath_len = p - vpath;
+               request->vpath = pestrndup(vpath, q - vpath, 1);
+               request->vpath_len = q - vpath;
                request->path_translated = buf;
-               request->path_translated_len = p - buf;
+               request->path_translated_len = q - buf;
        }
        request->sb = sb;
 } /* }}} */