]> granicus.if.org Git - php/commitdiff
[DOC]
authorGreg Beaver <cellog@php.net>
Thu, 7 Feb 2008 23:42:03 +0000 (23:42 +0000)
committerGreg Beaver <cellog@php.net>
Thu, 7 Feb 2008 23:42:03 +0000 (23:42 +0000)
refactor the $rewrites parameter in Phar::webPhar.  Now it is a callback
that accepts the path requested.  This callback should return the actual filename
requested as a string, or false to deny access as HTTP 403.
Also fix incorrect munging of SCRIPT_NAME variable in mungServer
More importantly, Phar::webPhar now finds the filename hidden in:
http://localhost/myphar.phar/internal/file.php/extra/stuff
as 'internal/file.php' in phar 'myphar.phar' with REQUEST_URI '/internal/file.php/extra/stuff'
this will allow pharring up apps that use REQUEST_URI for front controller stuff.

26 files changed:
ext/phar/phar_object.c
ext/phar/tests/frontcontroller10.phpt
ext/phar/tests/frontcontroller21.phpt
ext/phar/tests/frontcontroller3.phar
ext/phar/tests/frontcontroller3.phar.inc
ext/phar/tests/frontcontroller4.phar
ext/phar/tests/frontcontroller4.phar.inc
ext/phar/tests/frontcontroller6.phpt
ext/phar/tests/frontcontroller8.phpt
ext/phar/tests/tar/frontcontroller10.phar.phpt
ext/phar/tests/tar/frontcontroller21.phar.phpt
ext/phar/tests/tar/frontcontroller3.phar.inc
ext/phar/tests/tar/frontcontroller3.phar.tar
ext/phar/tests/tar/frontcontroller4.phar.inc
ext/phar/tests/tar/frontcontroller4.phar.tar
ext/phar/tests/tar/frontcontroller6.phar.phpt
ext/phar/tests/tar/frontcontroller8.phar.phpt
ext/phar/tests/withphar_web.phpt
ext/phar/tests/zip/frontcontroller10.phar.phpt
ext/phar/tests/zip/frontcontroller21.phar.phpt
ext/phar/tests/zip/frontcontroller3.phar.inc
ext/phar/tests/zip/frontcontroller3.phar.zip
ext/phar/tests/zip/frontcontroller4.phar.inc
ext/phar/tests/zip/frontcontroller4.phar.zip
ext/phar/tests/zip/frontcontroller6.phar.phpt
ext/phar/tests/zip/frontcontroller8.phar.phpt

index 434e7d9812e2cf62c037127438e7841e88b25755..09f59861481d743d7aa956ca04692c85cc3bbeef 100755 (executable)
@@ -74,7 +74,7 @@ static int phar_file_type(HashTable *mimes, char *file, char **mime_type TSRMLS_
 }
 /* }}} */
 
-static void phar_mung_server_vars(char *fname, char *entry, int entry_len, char *basename, int basename_len TSRMLS_DC)
+static void phar_mung_server_vars(char *fname, char *entry, int entry_len, char *basename, int basename_len, char *request_uri, int request_uri_len TSRMLS_DC)
 {
        zval **_SERVER, **stuff;
        char *path_info;
@@ -83,66 +83,67 @@ static void phar_mung_server_vars(char *fname, char *entry, int entry_len, char
        if (SUCCESS != zend_hash_find(&EG(symbol_table), "_SERVER", sizeof("_SERVER"), (void **) &_SERVER)) {
                return;
        }
-#define PHAR_MUNG_REPLACE(vname) \
-       if (zend_hash_exists(&(PHAR_GLOBALS->phar_SERVER_mung_list), #vname, sizeof(#vname)-1)) { \
-               if (SUCCESS == zend_hash_find(Z_ARRVAL_PP(_SERVER), #vname, sizeof(#vname), (void **) &stuff)) { \
-                       int code; \
-                       zval *temp; \
-                       char newname[sizeof("SCRIPT_FILENAME")+4]; \
-                                                       \
-                       path_info = Z_STRVAL_PP(stuff); \
-                       code = Z_STRLEN_PP(stuff); \
-                       Z_STRVAL_PP(stuff) = estrndup(Z_STRVAL_PP(stuff) + basename_len, Z_STRLEN_PP(stuff) - basename_len); \
-                       Z_STRLEN_PP(stuff) -= basename_len; \
-                                                       \
-                       MAKE_STD_ZVAL(temp); \
-                       Z_TYPE_P(temp) = IS_STRING; \
-                       Z_STRVAL_P(temp) = path_info; \
-                       Z_STRLEN_P(temp) = code; \
-                       memset(newname, 0, sizeof("SCRIPT_FILENAME")+4); \
-                       memcpy(newname, "PHAR_", 5); \
-                       memcpy(newname + 5, #vname, sizeof(#vname)); \
-                       zend_hash_update(Z_ARRVAL_PP(_SERVER), newname, strlen(newname)+1, (void *) &temp, sizeof(zval **), NULL); \
-               } \
-       }
 
        /* PATH_INFO and PATH_TRANSLATED should always be munged */
        if (SUCCESS == zend_hash_find(Z_ARRVAL_PP(_SERVER), "PATH_INFO", sizeof("PATH_INFO"), (void **) &stuff)) { 
                int code; 
                zval *temp; 
                char newname[] = "PHAR_PATH_INFO";
-                                               
+
                path_info = Z_STRVAL_PP(stuff); 
                code = Z_STRLEN_PP(stuff); 
-               Z_STRVAL_PP(stuff) = estrndup(Z_STRVAL_PP(stuff) + entry_len, Z_STRLEN_PP(stuff) - entry_len);
-               Z_STRLEN_PP(stuff) -= entry_len;
-                                               
+               ZVAL_STRINGL(*stuff, Z_STRVAL_PP(stuff) + entry_len, Z_STRLEN_PP(stuff) - entry_len - request_uri_len, 1);
+
                MAKE_STD_ZVAL(temp); 
-               Z_TYPE_P(temp) = IS_STRING; 
-               Z_STRVAL_P(temp) = path_info; 
-               Z_STRLEN_P(temp) = code; 
-               zend_hash_update(Z_ARRVAL_PP(_SERVER), newname, strlen(newname)+1, (void *) &temp, sizeof(zval **), NULL); 
+               ZVAL_STRINGL(temp, path_info, code, 0);
+               zend_hash_update(Z_ARRVAL_PP(_SERVER), newname, sizeof(newname), (void *) &temp, sizeof(zval **), NULL); 
        }
        if (SUCCESS == zend_hash_find(Z_ARRVAL_PP(_SERVER), "PATH_TRANSLATED", sizeof("PATH_TRANSLATED"), (void **) &stuff)) { 
                int code; 
                zval *temp; 
                char newname[] = "PHAR_PATH_TRANSLATED";
-                                               
+
                path_info = Z_STRVAL_PP(stuff); 
                code = Z_STRLEN_PP(stuff); 
                Z_STRLEN_PP(stuff) = spprintf(&(Z_STRVAL_PP(stuff)), 4096, "phar://%s%s", fname, entry);
-                                               
-               MAKE_STD_ZVAL(temp); 
-               Z_TYPE_P(temp) = IS_STRING; 
-               Z_STRVAL_P(temp) = path_info; 
-               Z_STRLEN_P(temp) = code; 
-               zend_hash_update(Z_ARRVAL_PP(_SERVER), newname, strlen(newname)+1, (void *) &temp, sizeof(zval **), NULL); 
+
+               MAKE_STD_ZVAL(temp);
+               ZVAL_STRINGL(temp, path_info, code, 0);
+               zend_hash_update(Z_ARRVAL_PP(_SERVER), newname, sizeof(newname), (void *) &temp, sizeof(zval **), NULL); 
        }
        if (!PHAR_GLOBALS->phar_SERVER_mung_list.arBuckets || !zend_hash_num_elements(&(PHAR_GLOBALS->phar_SERVER_mung_list))) {
                return;
        }
-       PHAR_MUNG_REPLACE(REQUEST_URI);
-       PHAR_MUNG_REPLACE(PHP_SELF);
+       if (zend_hash_exists(&(PHAR_GLOBALS->phar_SERVER_mung_list), "REQUEST_URI", sizeof("REQUEST_URI")-1)) {
+               if (SUCCESS == zend_hash_find(Z_ARRVAL_PP(_SERVER), "REQUEST_URI", sizeof("REQUEST_URI"), (void **) &stuff)) { 
+                       int code;
+                       zval *temp;
+                       char newname[] = "PHAR_REQUEST_URI";
+
+                       path_info = Z_STRVAL_PP(stuff);
+                       code = Z_STRLEN_PP(stuff);
+                       ZVAL_STRINGL(*stuff, Z_STRVAL_PP(stuff) + basename_len, Z_STRLEN_PP(stuff) - basename_len, 1);
+
+                       MAKE_STD_ZVAL(temp);
+                       ZVAL_STRINGL(temp, path_info, code, 0);
+                       zend_hash_update(Z_ARRVAL_PP(_SERVER), newname, sizeof(newname), (void *) &temp, sizeof(zval **), NULL);
+               }
+       }
+       if (zend_hash_exists(&(PHAR_GLOBALS->phar_SERVER_mung_list), "PHP_SELF", sizeof("PHP_SELF")-1)) {
+               if (SUCCESS == zend_hash_find(Z_ARRVAL_PP(_SERVER), "PHP_SELF", sizeof("PHP_SELF"), (void **) &stuff)) { 
+                       int code;
+                       zval *temp;
+                       char newname[] = "PHAR_PHP_SELF";
+
+                       path_info = Z_STRVAL_PP(stuff);
+                       code = Z_STRLEN_PP(stuff);
+                       ZVAL_STRINGL(*stuff, Z_STRVAL_PP(stuff) + basename_len, Z_STRLEN_PP(stuff) - basename_len, 1);
+
+                       MAKE_STD_ZVAL(temp);
+                       ZVAL_STRINGL(temp, path_info, code, 0);
+                       zend_hash_update(Z_ARRVAL_PP(_SERVER), newname, sizeof(newname), (void *) &temp, sizeof(zval **), NULL);
+               }
+       }
 
        if (zend_hash_exists(&(PHAR_GLOBALS->phar_SERVER_mung_list), "SCRIPT_NAME", sizeof("SCRIPT_NAME")-1)) {
                if (SUCCESS == zend_hash_find(Z_ARRVAL_PP(_SERVER), "SCRIPT_NAME", sizeof("SCRIPT_NAME"), (void **) &stuff)) { 
@@ -152,13 +153,15 @@ static void phar_mung_server_vars(char *fname, char *entry, int entry_len, char
                                                        
                        path_info = Z_STRVAL_PP(stuff); 
                        code = Z_STRLEN_PP(stuff); 
-                       Z_STRLEN_PP(stuff) = spprintf(&(Z_STRVAL_PP(stuff)), 4096, "phar://%s%s", fname, entry);
+                       if (entry[0] != '/') {
+                               Z_STRLEN_PP(stuff) = spprintf(&(Z_STRVAL_PP(stuff)), 4096, "phar://%s%s", fname, entry);
+                       } else {
+                               ZVAL_STRINGL(*stuff, entry, entry_len, 1);
+                       }
                                                        
-                       MAKE_STD_ZVAL(temp); 
-                       Z_TYPE_P(temp) = IS_STRING; 
-                       Z_STRVAL_P(temp) = path_info; 
-                       Z_STRLEN_P(temp) = code; 
-                       zend_hash_update(Z_ARRVAL_PP(_SERVER), newname, strlen(newname)+1, (void *) &temp, sizeof(zval **), NULL); 
+                       MAKE_STD_ZVAL(temp);
+                       ZVAL_STRINGL(temp, path_info, code, 0);
+                       zend_hash_update(Z_ARRVAL_PP(_SERVER), newname, sizeof(newname), (void *) &temp, sizeof(zval **), NULL); 
                } 
        }
 
@@ -167,21 +170,19 @@ static void phar_mung_server_vars(char *fname, char *entry, int entry_len, char
                        int code; 
                        zval *temp; 
                        char newname[] = "PHAR_SCRIPT_FILENAME";
-                                                       
+
                        path_info = Z_STRVAL_PP(stuff); 
                        code = Z_STRLEN_PP(stuff); 
                        Z_STRLEN_PP(stuff) = spprintf(&(Z_STRVAL_PP(stuff)), 4096, "phar://%s%s", fname, entry);
-                                                       
-                       MAKE_STD_ZVAL(temp); 
-                       Z_TYPE_P(temp) = IS_STRING; 
-                       Z_STRVAL_P(temp) = path_info; 
-                       Z_STRLEN_P(temp) = code; 
-                       zend_hash_update(Z_ARRVAL_PP(_SERVER), newname, strlen(newname)+1, (void *) &temp, sizeof(zval **), NULL); 
+
+                       MAKE_STD_ZVAL(temp);
+                       ZVAL_STRINGL(temp, path_info, code, 0);
+                       zend_hash_update(Z_ARRVAL_PP(_SERVER), newname, sizeof(newname), (void *) &temp, sizeof(zval **), NULL); 
                }
        }
 }
 
-static int phar_file_action(phar_entry_data *phar, char *mime_type, int code, char *entry, int entry_len, char *arch, int arch_len, char *basename, int basename_len TSRMLS_DC)
+static int phar_file_action(phar_entry_data *phar, char *mime_type, int code, char *entry, int entry_len, char *arch, int arch_len, char *basename, int basename_len, char *ru, int ru_len TSRMLS_DC)
 {
        char *name = NULL, buf[8192], *cwd;
        zend_syntax_highlighter_ini syntax_highlighter_ini;
@@ -203,8 +204,7 @@ static int phar_file_action(phar_entry_data *phar, char *mime_type, int code, ch
                        }
                        php_get_highlight_struct(&syntax_highlighter_ini);
 
-                       if (highlight_file(name, &syntax_highlighter_ini TSRMLS_CC) == FAILURE) {
-                       }
+                       highlight_file(name, &syntax_highlighter_ini TSRMLS_CC);
 
                        phar_entry_delref(phar TSRMLS_CC);
                        efree(name);
@@ -255,7 +255,7 @@ static int phar_file_action(phar_entry_data *phar, char *mime_type, int code, ch
                        return PHAR_MIME_OTHER;
                case PHAR_MIME_PHP:
                        if (basename) {
-                               phar_mung_server_vars(arch, entry, entry_len, basename, basename_len TSRMLS_CC);
+                               phar_mung_server_vars(arch, entry, entry_len, basename, basename_len, ru, ru_len TSRMLS_CC);
                                efree(basename);
                        }
                        phar_entry_delref(phar TSRMLS_CC);
@@ -327,7 +327,21 @@ static int phar_file_action(phar_entry_data *phar, char *mime_type, int code, ch
        return -1;
 }
 
-void phar_do_404(char *fname, int fname_len, char *f404, int f404_len, char *entry, int entry_len TSRMLS_DC)
+static void phar_do_403(char *entry, int entry_len TSRMLS_DC)
+{
+       sapi_header_line ctr = {0};
+
+       ctr.response_code = 403;
+       ctr.line_len = sizeof("HTTP/1.0 403 Access Denied");
+       ctr.line = "HTTP/1.0 403 Access Denied";
+       sapi_header_op(SAPI_HEADER_REPLACE, &ctr TSRMLS_CC);
+       sapi_send_headers(TSRMLS_C);
+       PHPWRITE("<html>\n <head>\n  <title>Access Denied</title>\n </head>\n <body>\n  <h1>403 - File ", sizeof("<html>\n <head>\n  <title>Access Denied</title>\n </head>\n <body>\n  <h1>403 - File ") - 1);
+       PHPWRITE(entry, entry_len);
+       PHPWRITE(" Access Denied</h1>\n </body>\n</html>", sizeof(" Access Denied</h1>\n </body>\n</html>") - 1);
+}
+
+static void phar_do_404(char *fname, int fname_len, char *f404, int f404_len, char *entry, int entry_len TSRMLS_DC)
 {
        int hi;
        phar_entry_data *phar;
@@ -339,7 +353,7 @@ void phar_do_404(char *fname, int fname_len, char *f404, int f404_len, char *ent
                        }
                        goto nofile;
                }
-               hi = phar_file_action(phar, "text/html", PHAR_MIME_PHP, f404, f404_len, fname, fname_len, NULL, 0 TSRMLS_CC);
+               hi = phar_file_action(phar, "text/html", PHAR_MIME_PHP, f404, f404_len, fname, fname_len, NULL, 0, NULL, 0 TSRMLS_CC);
        } else {
                sapi_header_line ctr = {0};
 nofile:
@@ -348,13 +362,54 @@ nofile:
                ctr.line = "HTTP/1.0 404 Not Found";
                sapi_header_op(SAPI_HEADER_REPLACE, &ctr TSRMLS_CC);
                sapi_send_headers(TSRMLS_C);
-               PHPWRITE("<html>\n <head>\n  <title>File Not Found<title>\n </head>\n <body>\n  <h1>404 - File ", sizeof("<html>\n <head>\n  <title>File Not Found<title>\n </head>\n <body>\n  <h1>404 - File ") - 1);
+               PHPWRITE("<html>\n <head>\n  <title>File Not Found</title>\n </head>\n <body>\n  <h1>404 - File ", sizeof("<html>\n <head>\n  <title>File Not Found</title>\n </head>\n <body>\n  <h1>404 - File ") - 1);
                PHPWRITE(entry, entry_len);
                PHPWRITE(" Not Found</h1>\n </body>\n</html>",  sizeof(" Not Found</h1>\n </body>\n</html>") - 1);
        }
 }
 
-/* {{{ proto void Phar::webPhar([string alias, [string index, [string f404, [array mimetypes, [array rewrites]]]]])
+static void phar_postprocess_ru_web(char *fname, int fname_len, char **entry,
+                                       int *entry_len, char **ru, int *ru_len TSRMLS_DC)
+{
+       char *e = *entry + 1, *u = NULL, *saveu = NULL;
+       int e_len = *entry_len - 1, u_len = 0;
+       phar_archive_data **pphar;
+
+       /* we already know we can retrieve the phar if we reach here */
+       zend_hash_find(&(PHAR_GLOBALS->phar_fname_map), fname, fname_len, (void **) &pphar);
+
+       do {
+               if (zend_hash_exists(&((*pphar)->manifest), e, e_len)) {
+                       if (u) {
+                               u[0] = '/';
+                               *ru = estrndup(u, u_len+1);
+                               u_len++;
+                               u[0] = '\0';
+                       } else {
+                               *ru = NULL;
+                       }
+                       *ru_len = u_len;
+                       *entry_len = e_len + 1;
+                       return;
+               }
+               if (u) {
+                       u[0] = '/';
+                       saveu = u;
+               }
+               u = strrchr(e, '/');
+               if (!u) {
+                       if (saveu) {
+                               saveu[0] = '/';
+                       }
+                       return;
+               }
+               u[0] = '\0';
+               u_len = strlen(u + 1);
+               e_len -= u_len + 1;
+       } while (1);
+}
+
+/* {{{ proto void Phar::webPhar([string alias, [string index, [string f404, [array mimetypes, [callback rewrites]]]]])
  * mapPhar for web-based phars. Reads the currently executed file (a phar)
  * and registers its manifest. When executed in the CLI or CGI command-line sapi,
  * this works exactly like mapPhar().  When executed by a web-based sapi, this
@@ -365,15 +420,14 @@ PHP_METHOD(Phar, webPhar)
 {
        HashTable mimetypes;
        phar_mime_type mime;
-       zval *mimeoverride = NULL, *rewrites = NULL;
-       char *alias = NULL, *error, *plain_map, *index_php, *f404 = NULL;
-       int alias_len = 0, ret, f404_len = 0, free_pathinfo = 0;
+       zval *mimeoverride = NULL, *rewrite = NULL;
+       char *alias = NULL, *error, *plain_map, *index_php, *f404 = NULL, *ru = NULL;
+       int alias_len = 0, ret, f404_len = 0, free_pathinfo = 0, ru_len = 0;
        char *fname, *basename, *path_info, *mime_type, *entry, *pt;
        int fname_len, entry_len, code, index_php_len = 0;
        phar_entry_data *phar;
-       zval **fd_ptr;
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s!s!saa", &alias, &alias_len, &index_php, &index_php_len, &f404, &f404_len, &mimeoverride, &rewrites) == FAILURE) {
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s!s!saz", &alias, &alias_len, &index_php, &index_php_len, &f404, &f404_len, &mimeoverride, &rewrite) == FAILURE) {
                return;
        }
 
@@ -435,23 +489,92 @@ PHP_METHOD(Phar, webPhar)
                        entry_len = 0;
                }
                pt = estrndup(testit, (pt - testit) + (fname_len - (basename - fname)));
-               goto skip_entry_dupe;
        } else {
                path_info = SG(request_info).request_uri;
-       }
 
-       if (!(pt = strstr(path_info, basename))) {
-               /* this can happen with rewrite rules - and we have no idea what to do then, so return */
-               return;
+               if (!(pt = strstr(path_info, basename))) {
+                       /* this can happen with rewrite rules - and we have no idea what to do then, so return */
+                       return;
+               }
+               entry_len = strlen(path_info);
+
+               entry_len -= (pt - path_info) + (fname_len - (basename - fname));
+               entry = estrndup(pt + (fname_len - (basename - fname)), entry_len);
+
+               pt = estrndup(path_info, (pt - path_info) + (fname_len - (basename - fname)));
        }
-       entry_len = strlen(path_info);
 
-       entry_len -= (pt - path_info) + (fname_len - (basename - fname));
-       entry = estrndup(pt + (fname_len - (basename - fname)), entry_len);
+       if (rewrite) {
+               zend_fcall_info fci;
+               zend_fcall_info_cache fcc;
+               zval *params, *retval_ptr, **zp[1];
+
+               MAKE_STD_ZVAL(params);
+               ZVAL_STRINGL(params, entry, entry_len, 1);
+               zp[0] = &params;
+
+               if (FAILURE == zend_fcall_info_init(rewrite, &fci, &fcc, NULL TSRMLS_CC)) {
+                       zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "phar error: invalid rewrite callback");
+                       if (free_pathinfo) {
+                               efree(path_info);
+                       }
+                       return;
+               }
+
+               fci.param_count = 1;
+               fci.params = zp;
+#if PHP_VERSION_ID < 50300
+               params->refcount++;
+#else
+               Z_ADDREF_P(params);
+#endif
+               fci.retval_ptr_ptr = &retval_ptr;
 
-       pt = estrndup(path_info, (pt - path_info) + (fname_len - (basename - fname)));
+               if (FAILURE == zend_call_function(&fci, &fcc TSRMLS_CC)) {
+                       if (!EG(exception)) {
+                               zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "phar error: failed to call rewrite callback");
+                       }
+                       if (free_pathinfo) {
+                               efree(path_info);
+                       }
+                       return;
+               }
+               if (!retval_ptr) {
+                       if (free_pathinfo) {
+                               efree(path_info);
+                       }
+                       zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "phar error: rewrite callback must return a string or false");
+                       return;
+               }
+               switch (Z_TYPE_P(retval_ptr)) {
+                       case IS_STRING :
+                               efree(entry);
+                               entry = Z_STRVAL_P(retval_ptr);
+                               entry_len = Z_STRLEN_P(retval_ptr);
+                               break;
+                       case IS_BOOL :
+                               phar_do_403(entry, entry_len TSRMLS_CC);
+                               if (free_pathinfo) {
+                                       efree(path_info);
+                               }
+                               zend_bailout();
+                               return;
+                       case IS_NULL :
+                               /* just use what we have now */
+                               break;
+                       default:
+                               efree(retval_ptr);
+                               if (free_pathinfo) {
+                                       efree(path_info);
+                               }
+                               zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "phar error: rewrite callback must return a string or false");
+                               return;
+               }
+       }
 
-skip_entry_dupe:
+       if (entry_len) {
+               phar_postprocess_ru_web(fname, fname_len, &entry, &entry_len, &ru, &ru_len TSRMLS_CC);
+       }
        if (!entry_len || (entry_len == 1 && entry[0] == '/')) {
                efree(entry);
                /* direct request */
@@ -507,24 +630,6 @@ skip_entry_dupe:
                }
        }
 
-       if (rewrites) {
-               /* check for "rewrite" urls */
-               if (SUCCESS == zend_hash_find(Z_ARRVAL_P(rewrites), entry, entry_len+1, (void **) &fd_ptr)) {
-                       if (IS_STRING != Z_TYPE_PP(fd_ptr)) {
-#ifdef PHP_WIN32
-                               efree(fname);
-#endif
-                               zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC, "phar rewrite value for \"%s\" was not a string", entry);
-                               return;
-                       }
-                       if (entry != index_php) {
-                               efree(entry);
-                       }
-                       entry = Z_STRVAL_PP(fd_ptr);
-                       entry_len = Z_STRLEN_PP(fd_ptr);
-               }
-       }
-
        if (FAILURE == phar_get_entry_data(&phar, fname, fname_len, entry, entry_len, "r", 0, &error TSRMLS_CC)) {
                phar_do_404(fname, fname_len, f404, f404_len, entry, entry_len TSRMLS_CC);
 #ifdef PHP_WIN32
@@ -649,7 +754,7 @@ skip_entry_dupe:
 
 no_mimes:
        code = phar_file_type(&mimetypes, entry, &mime_type TSRMLS_CC);
-       ret = phar_file_action(phar, mime_type, code, entry, entry_len, fname, fname_len, pt, strlen(pt) TSRMLS_CC);
+       ret = phar_file_action(phar, mime_type, code, entry, entry_len, fname, fname_len, pt, strlen(pt), ru, ru_len TSRMLS_CC);
        zend_hash_destroy(&mimetypes);
 #ifdef PHP_WIN32
        efree(fname);
index a96ffe11599250d50e0884ed404c6bf1f6c17dfb..195fdd8dfff0da1f3d0a6187bb8566fbc57861ec 100644 (file)
@@ -10,9 +10,13 @@ PATH_INFO=/hi
 frontcontroller4.phar
 --EXPECTHEADERS--
 Content-type: text/html
---EXPECTF--
-Fatal error: Uncaught exception 'UnexpectedValueException' with message 'phar rewrite value for "/hi" was not a string' in %sfrontcontroller10.php:2
-Stack trace:
-#0 %sfrontcontroller10.php(2): Phar::webPhar('whatever', 'index.php', '', Array, Array)
-#1 {main}
-  thrown in %sfrontcontroller10.php on line 2
\ No newline at end of file
+Status: 403 Access Denied
+--EXPECT--
+<html>
+ <head>
+  <title>Access Denied</title>
+ </head>
+ <body>
+  <h1>403 - File /hi Access Denied</h1>
+ </body>
+</html>
\ No newline at end of file
index 852320914256bb8a9d5bcb55ecc9dc3c407121f1..cfed28a98f34b780395d91d385f0b003c5225a99 100644 (file)
@@ -13,7 +13,7 @@ frontcontroller12.phar
 Content-type: text/html
 --EXPECTF--
 string(10) "/index.php"
-string(%d) "phar://%sfrontcontroller21.php/index.php"
+string(10) "/index.php"
 string(%d) "phar://%sfrontcontroller21.php/index.php"
 string(18) "/index.php?test=hi"
 string(32) "/frontcontroller21.php/index.php"
index 69908c02ab0d0ac55527f85d5de401b9e2c1e402..fc63fd4f1c4235975af5ce0916476d9c8d290609 100644 (file)
Binary files a/ext/phar/tests/frontcontroller3.phar and b/ext/phar/tests/frontcontroller3.phar differ
index 60d9ee07086dc25ae0e8cd8f55a621d76a219473..ef2bee282ac266527cec96d14e76bd99160e00f2 100644 (file)
@@ -5,7 +5,12 @@ $a['a.php'] = 'hio';
 $a['a.jpg'] = 'hio';
 $a['a.phps'] = '<?php function hio(){}';
 $a->setStub('<?php
-Phar::webPhar("whatever", "index.php", null, array(), array("/hi" => "a.phps"));
+function s($a)
+{
+    static $b = array("/hi" => "a.phps");
+    if (isset($b[$a])) return $b[$a];
+}
+Phar::webPhar("whatever", "/index.php", null, array(), "s");
 echo "oops did not run\n";
 var_dump($_ENV, $_SERVER);
 __HALT_COMPILER();');
index 34605264a21e3d44fca55e9b7f18709e50592a02..c9413ba875c8aea52ab799084046f4248fd65700 100644 (file)
Binary files a/ext/phar/tests/frontcontroller4.phar and b/ext/phar/tests/frontcontroller4.phar differ
index 5d9728cb194b74e09cbd6fd891117467b04d9a2b..5c6a43f9546ce6bbe2fc3ff22d991a51f2322339 100644 (file)
@@ -5,7 +5,13 @@ $a['a.php'] = 'hio';
 $a['a.jpg'] = 'hio';
 $a['a.phps'] = '<?php function hio(){}';
 $a->setStub('<?php
-Phar::webPhar("whatever", "index.php", null, array(), array("/hi" => true));
+function s($a)
+{
+    static $b = array("/hi" => false);
+    if (isset($b[$a])) return $b[$a];
+    return $a;
+}
+Phar::webPhar("whatever", "index.php", null, array(), "s");
 echo "oops did not run\n";
 var_dump($_ENV, $_SERVER);
 __HALT_COMPILER();');
index 7ec367285f1508badd3f45a1c4e9f055c1b0fa83..8e5d87a1bec9b2e36cfafcea9431d914a2de38d1 100644 (file)
@@ -13,7 +13,7 @@ Status: 404 Not Found
 --EXPECT--
 <html>
  <head>
-  <title>File Not Found<title>
+  <title>File Not Found</title>
  </head>
  <body>
   <h1>404 - File /notfound.php Not Found</h1>
index e48f231538ff3cb7afc90c91e1e0959c4ba1a625..088c7f9d8c7c873e9769f6f095c664461fb3b1ac 100644 (file)
@@ -13,9 +13,9 @@ Status: 404 Not Found
 --EXPECT--
 <html>
  <head>
-  <title>File Not Found<title>
+  <title>File Not Found</title>
  </head>
  <body>
-  <h1>404 - File index.php Not Found</h1>
+  <h1>404 - File /index.php Not Found</h1>
  </body>
 </html>
\ No newline at end of file
index b46fbbdf03ff1da72482105aeaf79af9d6251621..fbbe312d1ea20a158422fe044b66c5702d4dd2cf 100644 (file)
@@ -10,9 +10,13 @@ PATH_INFO=/hi
 frontcontroller4.phar.tar
 --EXPECTHEADERS--
 Content-type: text/html
---EXPECTF--
-Fatal error: Uncaught exception 'UnexpectedValueException' with message 'phar rewrite value for "/hi" was not a string' in %sfrontcontroller10.phar.php:2
-Stack trace:
-#0 %sfrontcontroller10.phar.php(2): Phar::webPhar('whatever', 'index.php', '', Array, Array)
-#1 {main}
-  thrown in %sfrontcontroller10.phar.php on line 2
\ No newline at end of file
+Status: 403 Access Denied
+--EXPECT--
+<html>
+ <head>
+  <title>Access Denied</title>
+ </head>
+ <body>
+  <h1>403 - File /hi Access Denied</h1>
+ </body>
+</html>
\ No newline at end of file
index f65690f1dcde70a607079a2c4babcc39cc97f561..2313cbba75aead667b32aa77f6cf1ad17e13e773 100644 (file)
@@ -13,7 +13,7 @@ frontcontroller12.phar.tar
 Content-type: text/html
 --EXPECTF--
 string(10) "/index.php"
-string(%d) "phar://%sfrontcontroller21.phar.php/index.php"
+string(10) "/index.php"
 string(%d) "phar://%sfrontcontroller21.phar.php/index.php"
 string(18) "/index.php?test=hi"
 string(37) "/frontcontroller21.phar.php/index.php"
index e4416b78d9dde14d16ca920809736de3b686f157..02525232b6bc570ab705a77a193f5d01e8e1576f 100644 (file)
@@ -5,7 +5,12 @@ $a['a.php'] = 'hio';
 $a['a.jpg'] = 'hio';
 $a['a.phps'] = '<?php function hio(){}';
 $a->setStub('<?php
-Phar::webPhar("whatever", "index.php", null, array(), array("/hi" => "a.phps"));
+function s($a)
+{
+    static $b = array("/hi" => "a.phps");
+    if (isset($b[$a])) return $b[$a];
+}
+Phar::webPhar("whatever", "/index.php", null, array(), "s");
 echo "oops did not run\n";
 var_dump($_ENV, $_SERVER);
 __HALT_COMPILER();');
index 59f32e1f47ebc332320fbecd50ccef527bbe723c..6f7361f5814be669e600db0eb786491cd15c5afd 100644 (file)
Binary files a/ext/phar/tests/tar/frontcontroller3.phar.tar and b/ext/phar/tests/tar/frontcontroller3.phar.tar differ
index d293f99dd535d188a4126d53778565bc01400f0c..eb1d56f0d4e3290bfbf8b9fcc1e4a5b4da73041f 100644 (file)
@@ -5,7 +5,13 @@ $a['a.php'] = 'hio';
 $a['a.jpg'] = 'hio';
 $a['a.phps'] = '<?php function hio(){}';
 $a->setStub('<?php
-Phar::webPhar("whatever", "index.php", null, array(), array("/hi" => true));
+function s($a)
+{
+    static $b = array("/hi" => false);
+    if (isset($b[$a])) return $b[$a];
+    return $a;
+}
+Phar::webPhar("whatever", "index.php", null, array(), "s");
 echo "oops did not run\n";
 var_dump($_ENV, $_SERVER);
 __HALT_COMPILER();');
index d494d98efee6d6128f0159fa30f80270ec306801..22ac39f35aa46d1c8d39915decee9a12f8e20c69 100644 (file)
Binary files a/ext/phar/tests/tar/frontcontroller4.phar.tar and b/ext/phar/tests/tar/frontcontroller4.phar.tar differ
index b523154a6e9c580dce205d1653da885bce239d2b..313630929b3b1e80d94dc193a5c7e130591619a6 100644 (file)
@@ -13,7 +13,7 @@ Status: 404 Not Found
 --EXPECT--
 <html>
  <head>
-  <title>File Not Found<title>
+  <title>File Not Found</title>
  </head>
  <body>
   <h1>404 - File /notfound.php Not Found</h1>
index 22ddf22af7bbad0b9648e2162293355ed6e6506b..0f6f50c70017fac067ca62e4c4e478c7e93ba437 100644 (file)
@@ -13,9 +13,9 @@ Status: 404 Not Found
 --EXPECT--
 <html>
  <head>
-  <title>File Not Found<title>
+  <title>File Not Found</title>
  </head>
  <body>
-  <h1>404 - File index.php Not Found</h1>
+  <h1>404 - File /index.php Not Found</h1>
  </body>
 </html>
\ No newline at end of file
index 887150de79c2683706b1206d1862338c033f5a82..68b0241dd93dc79bd1eabf5015ea5564bd6e4acb 100644 (file)
@@ -3,8 +3,9 @@ Phar: default web stub, with phar extension
 --SKIPIF--
 <?php if (!extension_loaded("phar")) die("skip");?>
 --ENV--
-SCRIPT_NAME=/withphar_web.php/web.php
+SCRIPT_NAME=/withphar_web.php
 REQUEST_URI=/withphar_web.php/web.php
+PATH_INFO=/web.php
 --FILE_EXTERNAL--
 nophar.phar
 --EXPECTHEADERS--
index 275c47f809bad96e71bef6e563f64d79a6abf3b6..76c2ca2c040de02ee940dd4032a663af46779e69 100644 (file)
@@ -10,9 +10,13 @@ PATH_INFO=/hi
 frontcontroller4.phar.zip
 --EXPECTHEADERS--
 Content-type: text/html
---EXPECTF--
-Fatal error: Uncaught exception 'UnexpectedValueException' with message 'phar rewrite value for "/hi" was not a string' in %sfrontcontroller10.phar.php:2
-Stack trace:
-#0 %sfrontcontroller10.phar.php(2): Phar::webPhar('whatever', 'index.php', '', Array, Array)
-#1 {main}
-  thrown in %sfrontcontroller10.phar.php on line 2
\ No newline at end of file
+Status: 403 Access Denied
+--EXPECT--
+<html>
+ <head>
+  <title>Access Denied</title>
+ </head>
+ <body>
+  <h1>403 - File /hi Access Denied</h1>
+ </body>
+</html>
\ No newline at end of file
index 3f3e9f1add3f39236a6fa64c6df76a2d2ea7c345..e1d8ea2fdf9e65ac33e1399677c50d03a9ad8639 100644 (file)
@@ -13,7 +13,7 @@ frontcontroller12.phar.zip
 Content-type: text/html
 --EXPECTF--
 string(10) "/index.php"
-string(%d) "phar://%sfrontcontroller21.phar.php/index.php"
+string(10) "/index.php"
 string(%d) "phar://%sfrontcontroller21.phar.php/index.php"
 string(18) "/index.php?test=hi"
 string(37) "/frontcontroller21.phar.php/index.php"
index a622b81f485685312713622d4be131ea2cf77c5b..8cd949aa74fba56f70aa987d261576a4531db257 100644 (file)
@@ -5,7 +5,12 @@ $a['a.php'] = 'hio';
 $a['a.jpg'] = 'hio';
 $a['a.phps'] = '<?php function hio(){}';
 $a->setStub('<?php
-Phar::webPhar("whatever", "index.php", null, array(), array("/hi" => "a.phps"));
+function s($a)
+{
+    static $b = array("/hi" => "a.phps");
+    if (isset($b[$a])) return $b[$a];
+}
+Phar::webPhar("whatever", "/index.php", null, array(), "s");
 echo "oops did not run\n";
 var_dump($_ENV, $_SERVER);
 __HALT_COMPILER();');
index 0ca3681e0b0cbe71e5b1f13bf75afd7500e4193a..5ac63f168292c8e5cae883469f1d7a2fe6382094 100644 (file)
Binary files a/ext/phar/tests/zip/frontcontroller3.phar.zip and b/ext/phar/tests/zip/frontcontroller3.phar.zip differ
index 62956ba2a2bd48b847dca11ba6e8ceada59634a6..d78399142e8ac7f5d1958afd60528b3d8803a4f6 100644 (file)
@@ -5,7 +5,13 @@ $a['a.php'] = 'hio';
 $a['a.jpg'] = 'hio';
 $a['a.phps'] = '<?php function hio(){}';
 $a->setStub('<?php
-Phar::webPhar("whatever", "index.php", null, array(), array("/hi" => true));
+function s($a)
+{
+    static $b = array("/hi" => false);
+    if (isset($b[$a])) return $b[$a];
+    return $a;
+}
+Phar::webPhar("whatever", "index.php", null, array(), "s");
 echo "oops did not run\n";
 var_dump($_ENV, $_SERVER);
 __HALT_COMPILER();');
index 08208a5565554ed3e2147ee064c6199159031bd1..70c70a1ddaf31e5e89fbe5809dd8a86d00167afe 100644 (file)
Binary files a/ext/phar/tests/zip/frontcontroller4.phar.zip and b/ext/phar/tests/zip/frontcontroller4.phar.zip differ
index c881d29661c1646fca93bb750dd3609b9f475a86..a1c8adfef061709b42c83d8e9aad8f6db8ecba81 100644 (file)
@@ -13,7 +13,7 @@ Status: 404 Not Found
 --EXPECT--
 <html>
  <head>
-  <title>File Not Found<title>
+  <title>File Not Found</title>
  </head>
  <body>
   <h1>404 - File /notfound.php Not Found</h1>
index 0e596ddd1e1ad3f1191a22f75997bf30bc67ba6a..08ee7544859317c8075ee197b2c792b2a59a23dd 100644 (file)
@@ -13,9 +13,9 @@ Status: 404 Not Found
 --EXPECT--
 <html>
  <head>
-  <title>File Not Found<title>
+  <title>File Not Found</title>
  </head>
  <body>
-  <h1>404 - File index.php Not Found</h1>
+  <h1>404 - File /index.php Not Found</h1>
  </body>
 </html>
\ No newline at end of file