laruence                                 Sun, 23 Oct 2011 02:54:06 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=318332

Log:
Fixed bug #60112 If URI does not contain a file, index.php is not served
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/"

Bug: https://bugs.php.net/60112 (Assigned) If URI does not contain a file, 
index.php is not served
      
Changed paths:
    U   php/php-src/branches/PHP_5_4/NEWS
    U   php/php-src/branches/PHP_5_4/sapi/cli/php_cli_server.c
    U   php/php-src/trunk/sapi/cli/php_cli_server.c

Modified: php/php-src/branches/PHP_5_4/NEWS
===================================================================
--- php/php-src/branches/PHP_5_4/NEWS   2011-10-23 00:07:01 UTC (rev 318331)
+++ php/php-src/branches/PHP_5_4/NEWS   2011-10-23 02:54:06 UTC (rev 318332)
@@ -3,6 +3,9 @@
 ?? ??? 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:

Modified: php/php-src/branches/PHP_5_4/sapi/cli/php_cli_server.c
===================================================================
--- php/php-src/branches/PHP_5_4/sapi/cli/php_cli_server.c      2011-10-23 
00:07:01 UTC (rev 318331)
+++ php/php-src/branches/PHP_5_4/sapi/cli/php_cli_server.c      2011-10-23 
02:54:06 UTC (rev 318332)
@@ -1248,13 +1248,31 @@
        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 @@
                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 @@
                                }
                        }
                        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;
 } /* }}} */

Modified: php/php-src/trunk/sapi/cli/php_cli_server.c
===================================================================
--- php/php-src/trunk/sapi/cli/php_cli_server.c 2011-10-23 00:07:01 UTC (rev 
318331)
+++ php/php-src/trunk/sapi/cli/php_cli_server.c 2011-10-23 02:54:06 UTC (rev 
318332)
@@ -1248,13 +1248,31 @@
        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 @@
                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 @@
                                }
                        }
                        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;
 } /* }}} */

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to