From b93b48663d910f96d705757b7b94be181c2a422e Mon Sep 17 00:00:00 2001 From: Greg Beaver Date: Tue, 8 Jan 2008 07:08:46 +0000 Subject: [PATCH] complete set of new tests for zip-based phars (need to test compression for zip-based phars) fix a whole bunch of zip-related bugs tar tests need some naming add phar information to error messages, fix existing tests to reflect this --- ext/phar/phar.c | 261 ++++++++++-------- ext/phar/phar_object.c | 53 +++- ext/phar/tar.c | 8 +- ext/phar/tests/033a.phpt | 2 +- ext/phar/tests/create_path_error.phpt | 8 +- ext/phar/tests/tar/033a.phpt | 2 +- .../tests/tar/open_for_write_newfile.phpt | 2 +- .../tests/tar/phar_buildfromiterator5.phpt | 6 +- .../tests/tar/phar_buildfromiterator6.phpt | 6 +- .../tests/tar/phar_buildfromiterator7.phpt | 6 +- .../tests/tar/phar_buildfromiterator9.phpt | 6 +- ext/phar/tests/tar/phar_stub_error.phpt | 2 +- ext/phar/tests/tar/rename.phpt | 2 +- ext/phar/tests/zip/033.phpt | 48 ++++ ext/phar/tests/zip/033a.phpt | 47 ++++ ext/phar/tests/zip/create_new_and_modify.phpt | 45 +++ ext/phar/tests/zip/create_new_phar_b.phpt | 27 ++ ext/phar/tests/zip/delete.phpt | 35 +++ ext/phar/tests/zip/delete_in_phar.phpt | 51 ++++ ext/phar/tests/zip/delete_in_phar_b.phpt | 49 ++++ .../tests/zip/delete_in_phar_confirm.phpt | 53 ++++ ext/phar/tests/zip/frontcontroller.phar.inc | 13 + ext/phar/tests/zip/frontcontroller.phar.zip | Bin 0 -> 625 bytes ext/phar/tests/zip/frontcontroller1.phar.phpt | 14 + ext/phar/tests/zip/frontcontroller10.phar.inc | 20 ++ .../tests/zip/frontcontroller10.phar.phpt | 17 ++ ext/phar/tests/zip/frontcontroller10.phar.zip | Bin 0 -> 471 bytes ext/phar/tests/zip/frontcontroller11.phar.inc | 20 ++ .../tests/zip/frontcontroller11.phar.phpt | 17 ++ ext/phar/tests/zip/frontcontroller11.phar.zip | Bin 0 -> 461 bytes ext/phar/tests/zip/frontcontroller12.phar.inc | 20 ++ .../tests/zip/frontcontroller12.phar.phpt | 17 ++ ext/phar/tests/zip/frontcontroller12.phar.zip | Bin 0 -> 465 bytes .../tests/zip/frontcontroller13.phar.phpt | 17 ++ .../tests/zip/frontcontroller14.phar.phpt | 14 + .../tests/zip/frontcontroller15.phar.phpt | 17 ++ .../tests/zip/frontcontroller16.phar.phpt | 14 + .../tests/zip/frontcontroller17.phar.phpt | 15 + .../tests/zip/frontcontroller18.phar.phpt | 15 + .../tests/zip/frontcontroller19.phar.phpt | 15 + ext/phar/tests/zip/frontcontroller2.phar.inc | 12 + ext/phar/tests/zip/frontcontroller2.phar.phpt | 13 + ext/phar/tests/zip/frontcontroller2.phar.zip | Bin 0 -> 531 bytes .../tests/zip/frontcontroller20.phar.phpt | 15 + .../tests/zip/frontcontroller21.phar.phpt | 20 ++ ext/phar/tests/zip/frontcontroller3.phar.inc | 12 + ext/phar/tests/zip/frontcontroller3.phar.phpt | 16 ++ ext/phar/tests/zip/frontcontroller3.phar.zip | Bin 0 -> 562 bytes ext/phar/tests/zip/frontcontroller4.phar.inc | 12 + ext/phar/tests/zip/frontcontroller4.phar.phpt | 13 + ext/phar/tests/zip/frontcontroller4.phar.zip | Bin 0 -> 561 bytes ext/phar/tests/zip/frontcontroller5.phar.inc | 12 + ext/phar/tests/zip/frontcontroller5.phar.phpt | 13 + ext/phar/tests/zip/frontcontroller5.phar.zip | Bin 0 -> 554 bytes ext/phar/tests/zip/frontcontroller6.phar.inc | 12 + ext/phar/tests/zip/frontcontroller6.phar.phpt | 20 ++ ext/phar/tests/zip/frontcontroller6.phar.zip | Bin 0 -> 559 bytes ext/phar/tests/zip/frontcontroller7.phar.inc | 12 + ext/phar/tests/zip/frontcontroller7.phar.phpt | 13 + ext/phar/tests/zip/frontcontroller7.phar.zip | Bin 0 -> 559 bytes ext/phar/tests/zip/frontcontroller8.phar.inc | 13 + ext/phar/tests/zip/frontcontroller8.phar.phpt | 20 ++ ext/phar/tests/zip/frontcontroller8.phar.zip | Bin 0 -> 684 bytes ext/phar/tests/zip/frontcontroller9.phar.inc | 14 + ext/phar/tests/zip/frontcontroller9.phar.phpt | 16 ++ ext/phar/tests/zip/frontcontroller9.phar.zip | Bin 0 -> 697 bytes ext/phar/tests/zip/make_invalid_tar.php.inc | 12 + .../tests/zip/open_for_write_existing.phpt | 38 +++ .../tests/zip/open_for_write_existing_b.phpt | 49 ++++ .../tests/zip/open_for_write_existing_c.phpt | 43 +++ .../tests/zip/open_for_write_newfile.phpt | 40 +++ .../tests/zip/open_for_write_newfile_b.phpt | 56 ++++ .../tests/zip/open_for_write_newfile_c.phpt | 50 ++++ .../tests/zip/phar_begin_setstub_commit.phpt | 51 ++++ .../tests/zip/phar_buildfromiterator4.phpt | 66 +++++ .../tests/zip/phar_buildfromiterator5.phpt | 59 ++++ .../tests/zip/phar_buildfromiterator6.phpt | 60 ++++ .../tests/zip/phar_buildfromiterator7.phpt | 60 ++++ .../tests/zip/phar_buildfromiterator8.phpt | 73 +++++ .../tests/zip/phar_buildfromiterator9.phpt | 65 +++++ ext/phar/tests/zip/phar_commitwrite.phpt | 44 +++ ext/phar/tests/zip/phar_copy.phpt | 56 ++++ ext/phar/tests/zip/phar_magic.phpt | 32 +++ ext/phar/tests/zip/phar_setalias.phpt | 42 +++ ext/phar/tests/zip/phar_setalias2.phpt | 51 ++++ ext/phar/tests/zip/phar_stub_error.phpt | 62 +++++ ext/phar/tests/zip/refcount1.phpt | 71 +++++ ext/phar/tests/zip/refcount1_5_2.phpt | 63 +++++ ext/phar/tests/zip/rename.phpt | 40 +++ ext/phar/tests/zip/tarmaker.php.inc | 70 +++++ 90 files changed, 2329 insertions(+), 146 deletions(-) create mode 100644 ext/phar/tests/zip/033.phpt create mode 100644 ext/phar/tests/zip/033a.phpt create mode 100644 ext/phar/tests/zip/create_new_and_modify.phpt create mode 100644 ext/phar/tests/zip/create_new_phar_b.phpt create mode 100644 ext/phar/tests/zip/delete.phpt create mode 100644 ext/phar/tests/zip/delete_in_phar.phpt create mode 100644 ext/phar/tests/zip/delete_in_phar_b.phpt create mode 100644 ext/phar/tests/zip/delete_in_phar_confirm.phpt create mode 100644 ext/phar/tests/zip/frontcontroller.phar.inc create mode 100644 ext/phar/tests/zip/frontcontroller.phar.zip create mode 100644 ext/phar/tests/zip/frontcontroller1.phar.phpt create mode 100644 ext/phar/tests/zip/frontcontroller10.phar.inc create mode 100644 ext/phar/tests/zip/frontcontroller10.phar.phpt create mode 100644 ext/phar/tests/zip/frontcontroller10.phar.zip create mode 100644 ext/phar/tests/zip/frontcontroller11.phar.inc create mode 100644 ext/phar/tests/zip/frontcontroller11.phar.phpt create mode 100644 ext/phar/tests/zip/frontcontroller11.phar.zip create mode 100644 ext/phar/tests/zip/frontcontroller12.phar.inc create mode 100644 ext/phar/tests/zip/frontcontroller12.phar.phpt create mode 100644 ext/phar/tests/zip/frontcontroller12.phar.zip create mode 100644 ext/phar/tests/zip/frontcontroller13.phar.phpt create mode 100644 ext/phar/tests/zip/frontcontroller14.phar.phpt create mode 100644 ext/phar/tests/zip/frontcontroller15.phar.phpt create mode 100644 ext/phar/tests/zip/frontcontroller16.phar.phpt create mode 100644 ext/phar/tests/zip/frontcontroller17.phar.phpt create mode 100644 ext/phar/tests/zip/frontcontroller18.phar.phpt create mode 100644 ext/phar/tests/zip/frontcontroller19.phar.phpt create mode 100644 ext/phar/tests/zip/frontcontroller2.phar.inc create mode 100644 ext/phar/tests/zip/frontcontroller2.phar.phpt create mode 100644 ext/phar/tests/zip/frontcontroller2.phar.zip create mode 100644 ext/phar/tests/zip/frontcontroller20.phar.phpt create mode 100644 ext/phar/tests/zip/frontcontroller21.phar.phpt create mode 100644 ext/phar/tests/zip/frontcontroller3.phar.inc create mode 100644 ext/phar/tests/zip/frontcontroller3.phar.phpt create mode 100644 ext/phar/tests/zip/frontcontroller3.phar.zip create mode 100644 ext/phar/tests/zip/frontcontroller4.phar.inc create mode 100644 ext/phar/tests/zip/frontcontroller4.phar.phpt create mode 100644 ext/phar/tests/zip/frontcontroller4.phar.zip create mode 100644 ext/phar/tests/zip/frontcontroller5.phar.inc create mode 100644 ext/phar/tests/zip/frontcontroller5.phar.phpt create mode 100644 ext/phar/tests/zip/frontcontroller5.phar.zip create mode 100644 ext/phar/tests/zip/frontcontroller6.phar.inc create mode 100644 ext/phar/tests/zip/frontcontroller6.phar.phpt create mode 100644 ext/phar/tests/zip/frontcontroller6.phar.zip create mode 100644 ext/phar/tests/zip/frontcontroller7.phar.inc create mode 100644 ext/phar/tests/zip/frontcontroller7.phar.phpt create mode 100644 ext/phar/tests/zip/frontcontroller7.phar.zip create mode 100644 ext/phar/tests/zip/frontcontroller8.phar.inc create mode 100644 ext/phar/tests/zip/frontcontroller8.phar.phpt create mode 100644 ext/phar/tests/zip/frontcontroller8.phar.zip create mode 100644 ext/phar/tests/zip/frontcontroller9.phar.inc create mode 100644 ext/phar/tests/zip/frontcontroller9.phar.phpt create mode 100644 ext/phar/tests/zip/frontcontroller9.phar.zip create mode 100644 ext/phar/tests/zip/make_invalid_tar.php.inc create mode 100644 ext/phar/tests/zip/open_for_write_existing.phpt create mode 100755 ext/phar/tests/zip/open_for_write_existing_b.phpt create mode 100755 ext/phar/tests/zip/open_for_write_existing_c.phpt create mode 100644 ext/phar/tests/zip/open_for_write_newfile.phpt create mode 100755 ext/phar/tests/zip/open_for_write_newfile_b.phpt create mode 100755 ext/phar/tests/zip/open_for_write_newfile_c.phpt create mode 100755 ext/phar/tests/zip/phar_begin_setstub_commit.phpt create mode 100644 ext/phar/tests/zip/phar_buildfromiterator4.phpt create mode 100644 ext/phar/tests/zip/phar_buildfromiterator5.phpt create mode 100644 ext/phar/tests/zip/phar_buildfromiterator6.phpt create mode 100644 ext/phar/tests/zip/phar_buildfromiterator7.phpt create mode 100644 ext/phar/tests/zip/phar_buildfromiterator8.phpt create mode 100644 ext/phar/tests/zip/phar_buildfromiterator9.phpt create mode 100644 ext/phar/tests/zip/phar_commitwrite.phpt create mode 100644 ext/phar/tests/zip/phar_copy.phpt create mode 100644 ext/phar/tests/zip/phar_magic.phpt create mode 100644 ext/phar/tests/zip/phar_setalias.phpt create mode 100644 ext/phar/tests/zip/phar_setalias2.phpt create mode 100755 ext/phar/tests/zip/phar_stub_error.phpt create mode 100644 ext/phar/tests/zip/refcount1.phpt create mode 100755 ext/phar/tests/zip/refcount1_5_2.phpt create mode 100644 ext/phar/tests/zip/rename.phpt create mode 100644 ext/phar/tests/zip/tarmaker.php.inc diff --git a/ext/phar/phar.c b/ext/phar/phar.c index 0a0568f312..f828cb65b5 100644 --- a/ext/phar/phar.c +++ b/ext/phar/phar.c @@ -445,25 +445,16 @@ phar_entry_info *phar_get_entry_info_dir(phar_archive_data *phar, char *path, in return NULL; } if (SUCCESS == zend_hash_find(&phar->manifest, path, path_len, (void**)&entry)) { -#if HAVE_PHAR_ZIP - if (phar->is_zip) { - /* construct phar_entry_info JIT */ - if (path[path_len - 1] == '/') { - if (!dir) { - if (error) { - spprintf(error, 4096, "phar error: path \"%s\" is a directory", path); - } - return NULL; - } - - entry->is_dir = 1; - } - } -#endif if (entry->is_deleted) { /* entry is deleted, but has not been flushed to disk yet */ return NULL; } + if (entry->is_dir && !dir) { + if (error) { + spprintf(error, 4096, "phar error: path \"%s\" is a directory", path); + } + return NULL; + } return entry; } if (dir) { @@ -521,7 +512,7 @@ typedef struct { } php_stream_memory_data; #endif -/* this is only called for non-zip-based phars */ +/* this is only called for non-zip/tar-based phars */ static int phar_open_entry_file(phar_archive_data *phar, phar_entry_info *entry, char **error TSRMLS_DC) /* {{{ */ { if (error) { @@ -573,7 +564,7 @@ int phar_get_entry_data(phar_entry_data **ret, char *fname, int fname_len, char } if (for_write && PHAR_G(readonly)) { if (error) { - spprintf(error, 0, "phar error: file \"%s\" cannot opened for writing, disabled by ini setting", fname); + spprintf(error, 4096, "phar error: file \"%s\" in phar \"%s\" cannot be opened for writing, disabled by ini setting", path, fname); } return FAILURE; } @@ -582,7 +573,7 @@ int phar_get_entry_data(phar_entry_data **ret, char *fname, int fname_len, char } if (!path_len) { if (error) { - spprintf(error, 0, "phar error: file \"\" cannot be empty"); + spprintf(error, 4096, "phar error: file \"\" in phar \"%s\" cannot be empty", fname); } return FAILURE; } @@ -594,13 +585,13 @@ int phar_get_entry_data(phar_entry_data **ret, char *fname, int fname_len, char } if (entry->is_modified && !for_write) { if (error) { - spprintf(error, 4096, "phar error: file \"%s\" cannot opened for reading, writable file pointers are open", fname); + spprintf(error, 4096, "phar error: file \"%s\" in phar \"%s\" cannot be opened for reading, writable file pointers are open", path, fname); } return FAILURE; } if (entry->fp_refcount && for_write) { if (error) { - spprintf(error, 4096, "phar error: file \"%s\" cannot opened for writing, readable file pointers are open", fname); + spprintf(error, 4096, "phar error: file \"%s\" in phar \"%s\" cannot be opened for writing, readable file pointers are open", path, fname); } return FAILURE; } @@ -608,19 +599,6 @@ int phar_get_entry_data(phar_entry_data **ret, char *fname, int fname_len, char if (!for_create) { return FAILURE; } -#if HAVE_PHAR_ZIP - if (entry->is_zip) { - /* for new files, start with an empty string */ - struct zip_source *s = zip_source_buffer(entry->phar->zip, (void *)"", 0, 0); - if (-1 == zip_replace(entry->phar->zip, entry->index, s)) { - if (error) { - spprintf(error, 4096, "phar error: zip-based phar \"%s\" entry \"%s\" error \"%s\"", entry->phar->fname, fname, zip_strerror(phar->zip)); - } - zip_error_clear(phar->zip); - return FAILURE; - } - } -#endif entry->is_deleted = 0; } *ret = (phar_entry_data *) emalloc(sizeof(phar_entry_data)); @@ -656,7 +634,7 @@ int phar_get_entry_data(phar_entry_data **ret, char *fname, int fname_len, char efree(*ret); *ret = NULL; if (error) { - spprintf(error, 0, "phar error: file \"%s\" cannot opened for writing, no truncate support", fname); + spprintf(error, 0, "phar error: file \"%s\" cannot be opened for writing, no truncate support", fname); } return FAILURE; } @@ -666,7 +644,7 @@ int phar_get_entry_data(phar_entry_data **ret, char *fname, int fname_len, char efree(*ret); *ret = NULL; if (error) { - spprintf(error, 0, "phar error: file \"%s\" cannot opened for writing, no truncate support", fname); + spprintf(error, 0, "phar error: file \"%s\" cannot be opened for writing, no truncate support", fname); } return FAILURE; } @@ -802,29 +780,11 @@ phar_entry_data *phar_get_or_create_entry_data(char *fname, int fname_len, char etemp.phar = phar; #if HAVE_PHAR_ZIP if (phar->is_zip) { - int zindex; etemp.is_zip = 1; /* prevent attempts to check the CRC */ etemp.is_crc_checked = 1; - /* for new files, start with an empty string */ - struct zip_source *s = zip_source_buffer(phar->zip, (void *)"", 0, 0); - if (-1 == (zindex = zip_add(phar->zip, path, s))) { - if (error) { - spprintf(error, 4096, "phar error: zip-based phar \"%s\" entry \"%s\" error \"%s\"", path, phar->fname, zip_strerror(phar->zip)); - } - zip_error_clear(phar->zip); - return NULL; - } - etemp.index = zindex; - etemp.filename = (char *) zip_get_name(phar->zip, zindex, 0); - if (NULL == etemp.filename) { - if (error) { - spprintf(error, 4096, "phar error: zip-based phar \"%s\" entry \"%s\" error \"%s\"", path, phar->fname, zip_strerror(phar->zip)); - } - zip_error_clear(phar->zip); - return NULL; - } - etemp.filename = estrndup(etemp.filename, strlen(etemp.filename)); + etemp.index = -1; + etemp.filename = estrndup(path, path_len); } else { etemp.is_tar = phar->is_tar; etemp.tar_type = '0'; @@ -833,9 +793,7 @@ phar_entry_data *phar_get_or_create_entry_data(char *fname, int fname_len, char #else etemp.filename = estrndup(path, path_len); #endif - zend_hash_add(&phar->manifest, etemp.filename, path_len, (void*)&etemp, sizeof(phar_entry_info), NULL); - /* retrieve the phar manifest copy */ - entry = phar_get_entry_info(phar, path, path_len, error TSRMLS_CC); + zend_hash_add(&phar->manifest, etemp.filename, path_len, (void*)&etemp, sizeof(phar_entry_info), (void **) &entry); if (!entry) { return NULL; @@ -1048,7 +1006,7 @@ int phar_open_zipfile(char *fname, int fname_len, char *alias, int alias_len, ph phar_unixify_path_separators(mydata->fname, fname_len); #endif mydata->fname_len = fname_len; - if (-1 != (phar_alias_index = zip_name_locate(zip, "./phar/alias.txt", 0))) { + if (-1 != (phar_alias_index = zip_name_locate(zip, ".phar/alias.txt", 0))) { struct zip_file *zf = zip_fopen_index(zip, phar_alias_index, 0); int tmp_len; @@ -1108,7 +1066,7 @@ int phar_open_zipfile(char *fname, int fname_len, char *alias, int alias_len, ph entry.uncompressed_filesize = zs.size; entry.crc32 = zs.crc; entry.timestamp = (php_uint32) zs.mtime; - entry.flags = 0; + entry.flags = PHAR_ENT_PERM_DEF_FILE; switch (zs.comp_method) { case ZIP_CM_DEFLATE : /* if we have zip, we have zlib decompression */ @@ -1145,7 +1103,7 @@ int phar_open_zipfile(char *fname, int fname_len, char *alias, int alias_len, ph mydata->manifest.arBuckets = NULL; efree(mydata); if (error) { - spprintf(error, 0, "bz2 extension is required for gz compressed zip-based .phar file \"%s\"", fname); + spprintf(error, 0, "bz2 extension is required for Bzip2 compressed zip-based .phar file \"%s\"", fname); } return FAILURE; } @@ -1156,6 +1114,13 @@ int phar_open_zipfile(char *fname, int fname_len, char *alias, int alias_len, ph } entry.index = i; entry.filename_len = strlen(name); + if (name[entry.filename_len - 1] == '/') { + entry.is_dir = 1; + entry.filename_len--; + entry.flags |= PHAR_ENT_PERM_DEF_DIR; + } else { + entry.is_dir = 0; + } entry.filename = estrndup(name, entry.filename_len); /* get file metadata */ metadata = (char *) zip_get_file_comment(zip, i, &metadata_len, 0); @@ -1170,7 +1135,7 @@ int phar_open_zipfile(char *fname, int fname_len, char *alias, int alias_len, ph } else { entry.metadata = NULL; } - zend_hash_add(&mydata->manifest, name, strlen(name), (void *)&entry,sizeof(phar_entry_info), NULL); + zend_hash_add(&mydata->manifest, name, entry.filename_len, (void *)&entry,sizeof(phar_entry_info), NULL); } } /* ignore all errors in loading up manifest */ @@ -1666,17 +1631,19 @@ int phar_open_or_create_zip(char *fname, int fname_len, char *alias, int alias_l { #if HAVE_PHAR_ZIP phar_archive_data *phar; - int ret = phar_create_or_parse_filename(fname, fname_len, alias, alias_len, options, pphar, error TSRMLS_CC); + int ret = phar_create_or_parse_filename(fname, fname_len, alias, alias_len, options, &phar, error TSRMLS_CC); int register_alias; + if (pphar) { + *pphar = phar; + } if (FAILURE == ret) { return FAILURE; } - if ((*pphar)->is_zip) { + if (phar->is_zip) { return ret; } - phar = *pphar; if (phar->is_brandnew) { int *errorp; phar->is_zip = 1; @@ -1766,7 +1733,6 @@ int phar_open_or_create_filename(char *fname, int fname_len, char *alias, int al int phar_create_or_parse_filename(char *fname, int fname_len, char *alias, int alias_len, int options, phar_archive_data** pphar, char **error TSRMLS_DC) /* {{{ */ { phar_archive_data *mydata; - char *my_realpath; int register_alias; php_stream *fp; @@ -1809,31 +1775,30 @@ int phar_create_or_parse_filename(char *fname, int fname_len, char *alias, int a } return FAILURE; } - /* re-open for writing */ - fp = php_stream_open_wrapper(fname, "r+b", IGNORE_URL|STREAM_MUST_SEEK|0, NULL); /* set up our manifest */ mydata = ecalloc(sizeof(phar_archive_data), 1); - if (pphar) { - *pphar = mydata; - } - zend_hash_init(&mydata->manifest, sizeof(phar_entry_info), - zend_get_hash_value, destroy_phar_manifest, 0); - my_realpath = NULL; - my_realpath = expand_filepath(fname, my_realpath TSRMLS_CC); - if (my_realpath) { - fname_len = strlen(my_realpath); + + /* re-open for writing */ + fp = php_stream_open_wrapper(fname, "r+b", IGNORE_URL|STREAM_MUST_SEEK|0, &mydata->fname); + if (mydata->fname) { + fname = mydata->fname; #ifdef PHP_WIN32 - phar_unixify_path_separators(my_realpath, fname_len); + phar_unixify_path_separators(fname, fname_len); #endif - fname = my_realpath; - mydata->fname = my_realpath; + fname_len = strlen(mydata->fname); } else { mydata->fname = estrndup(fname, fname_len); #ifdef PHP_WIN32 phar_unixify_path_separators(mydata->fname, fname_len); #endif } + + if (pphar) { + *pphar = mydata; + } + zend_hash_init(&mydata->manifest, sizeof(phar_entry_info), + zend_get_hash_value, destroy_phar_manifest, 0); mydata->fname_len = fname_len; mydata->alias = alias ? estrndup(alias, alias_len) : estrndup(mydata->fname, fname_len); mydata->alias_len = alias ? alias_len : fname_len; @@ -2517,6 +2482,7 @@ phar_entry_info * phar_open_jit(phar_archive_data *phar, phar_entry_info *entry, } } while (got == 8192); zip_fclose(entry->zip); + entry->zip = NULL; php_stream_seek(fp, 0, SEEK_SET); /* now use a decompression filter to inflate into our temp file */ @@ -2783,8 +2749,7 @@ static php_stream * phar_wrapper_open_url(php_stream_wrapper *wrapper, char *pat return NULL; } - idata->internal_file = phar_open_jit(idata->phar, idata->internal_file, fp, &error, idata->for_write TSRMLS_CC); - if (!idata->internal_file) { + if (!phar_open_jit(idata->phar, idata->internal_file, fp, &error, idata->for_write TSRMLS_CC)) { php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, error); efree(error); phar_entry_delref(idata TSRMLS_CC); @@ -3074,6 +3039,12 @@ static ssize_t phar_zip_source(void *state, void *data, size_t len, enum zip_sou sb->mtime = time(NULL); sb->size = entry->uncompressed_filesize; return sizeof(struct zip_stat); + case ZIP_SOURCE_FREE: + entry->is_modified = 0; + if (entry->fp && entry->fp_refcount == 0) { + php_stream_close(entry->fp); + entry->fp = NULL; + } default: return len; } @@ -3092,7 +3063,15 @@ static int phar_zip_reconstruct_apply(void *data TSRMLS_DC) /* {{{ */ return ZEND_HASH_APPLY_KEEP; } } - entry->index = zip_name_locate(entry->phar->zip, entry->filename, 0); + if (entry->is_dir) { + char *myname = estrndup(entry->filename, entry->filename_len+2); + myname[entry->filename_len] = '/'; + myname[entry->filename_len+1] = '\0'; + entry->index = zip_name_locate(entry->phar->zip, entry->filename, ZIP_FL_UNCHANGED); + efree(myname); + } else { + entry->index = zip_name_locate(entry->phar->zip, entry->filename, ZIP_FL_UNCHANGED); + } return ZEND_HASH_APPLY_KEEP; } @@ -3112,11 +3091,18 @@ static int phar_zip_changed_apply(void *data TSRMLS_DC) /* {{{ */ if (entry->is_modified) { ssize_t (*cb)(void *state, void *data, size_t len, enum zip_source_cmd cmd) = phar_zip_source; if (entry->fp) { + php_stream *fp = entry->fp; struct zip_source *s = zip_source_function(entry->phar->zip, cb, entry); - if (-1 == zip_replace(entry->phar->zip, entry->index, s)) { + + /* we have to prevent free of this fp by mistake */ + entry->fp = NULL; + if (-1 == (entry->index = _zip_replace(entry->phar->zip, entry->index, (const char *) entry->filename, s))) { zip_error_clear(entry->phar->zip); return ZEND_HASH_APPLY_REMOVE; } + /* now restore fp and is_modified */ + entry->fp = fp; + entry->is_modified = 1; } /* set file metadata */ @@ -3151,15 +3137,14 @@ int phar_zip_flush(phar_archive_data *archive, char *user_stub, long len, char * php_serialize_data_t metadata_hash; int free_user_stub; int phar_stub_index, phar_alias_index; + phar_entry_info entry = {0}; - /* save modified files to the zip */ - zend_hash_apply(&archive->manifest, phar_zip_changed_apply TSRMLS_CC); - if (archive->zip->error.str) { - if (error) { - spprintf(error, 4096, "phar zip flush of \"%s\" failed: %s", archive->fname, zip_strerror(archive->zip)); - } - return EOF; - } + entry.flags = PHAR_ENT_PERM_DEF_FILE; + entry.timestamp = time(NULL); + entry.is_modified = 1; + entry.is_crc_checked = 1; + entry.is_zip = 1; + entry.phar = archive; /* set phar metadata */ main_metadata_str.c = 0; @@ -3175,28 +3160,40 @@ int phar_zip_flush(phar_archive_data *archive, char *user_stub, long len, char * /* set alias */ if (archive->is_explicit_alias) { - struct zip_source *source; phar_alias_index = zip_name_locate(archive->zip, ".phar/alias.txt", 0); - if (NULL == (source = zip_source_buffer(archive->zip, archive->alias, archive->alias_len, 0)) || - (-1 == phar_alias_index && -1 == zip_add(archive->zip, ".phar/alias.txt", source)) || - (-1 != phar_alias_index && -1 == zip_replace(archive->zip, phar_alias_index, source))) { + entry.fp = php_stream_fopen_tmpfile(); + if (archive->alias_len != php_stream_write(entry.fp, archive->alias, archive->alias_len)) { if (error) { - spprintf(error, 0, "unable to set alias in new zip-based phar \"%s\": %s", archive->fname, zip_strerror(archive->zip)); + spprintf(error, 0, "unable to set alias in new zip-based phar \"%s\"", archive->fname); + } + return EOF; + } + entry.uncompressed_filesize = sizeof(newstub) - 1; + entry.filename = estrndup(".phar/alias.txt", sizeof(".phar/alias.txt")-1); + entry.filename_len = sizeof(".phar/alias.txt")-1; + entry.is_modified = 1; + entry.index = phar_alias_index; + if (SUCCESS != zend_hash_update(&archive->manifest, entry.filename, entry.filename_len, (void*)&entry, sizeof(phar_entry_info), NULL)) { + if (error) { + spprintf(error, 0, "unable to set alias in new zip-based phar \"%s\"", archive->fname); } - zip_error_clear(archive->zip); return EOF; } } + /* register alias */ + if (archive->alias_len) { + phar_get_archive(&archive, archive->fname, archive->fname_len, archive->alias, archive->alias_len, NULL TSRMLS_CC); + } + /* set stub */ phar_stub_index = zip_name_locate(archive->zip, ".phar/stub.php", 0); zip_error_clear(archive->zip); if (user_stub) { - struct zip_source *source; if (len < 0) { /* resource passed in */ if (!(php_stream_from_zval_no_verify(stubfile, (zval **)user_stub))) { if (error) { - spprintf(error, 0, "unable to access resource to copy stub to new phar \"%s\"", archive->fname); + spprintf(error, 0, "unable to access resource to copy stub to new zip-based phar \"%s\"", archive->fname); } return EOF; } @@ -3208,7 +3205,7 @@ int phar_zip_flush(phar_archive_data *archive, char *user_stub, long len, char * user_stub = 0; if (!(len = php_stream_copy_to_mem(stubfile, &user_stub, len, 0)) || !user_stub) { if (error) { - spprintf(error, 0, "unable to read resource to copy stub to new phar \"%s\"", archive->fname); + spprintf(error, 0, "unable to read resource to copy stub to new zip-based phar \"%s\"", archive->fname); } return EOF; } @@ -3219,7 +3216,7 @@ int phar_zip_flush(phar_archive_data *archive, char *user_stub, long len, char * if ((pos = strstr(user_stub, "__HALT_COMPILER();")) == NULL) { if (error) { - spprintf(error, 0, "illegal stub for phar \"%s\"", archive->fname); + spprintf(error, 0, "illegal stub for zip-based phar \"%s\"", archive->fname); } if (free_user_stub) { efree(user_stub); @@ -3227,35 +3224,71 @@ int phar_zip_flush(phar_archive_data *archive, char *user_stub, long len, char * return EOF; } len = pos - user_stub + 18; - if (NULL == (source = zip_source_buffer(archive->zip, user_stub, len, 0)) || - (-1 == phar_stub_index && -1 == zip_add(archive->zip, ".phar/stub.php", source)) || - (-1 != phar_stub_index && -1 == zip_replace(archive->zip, phar_stub_index, source))) { + entry.fp = php_stream_fopen_tmpfile(); + entry.uncompressed_filesize = len + 5; + + if ((size_t)len != php_stream_write(entry.fp, user_stub, len) + || 5 != php_stream_write(entry.fp, " ?>\r\n", 5)) { if (error) { - spprintf(error, 0, "unable to create stub from string in new zip-based phar \"%s\": %s", archive->fname, zip_strerror(archive->zip)); + spprintf(error, 0, "unable to create stub from string in new zip-based phar \"%s\"", archive->fname); } if (free_user_stub) { efree(user_stub); } - zip_error_clear(archive->zip); + php_stream_close(entry.fp); + return EOF; + } + entry.filename = estrndup(".phar/stub.php", sizeof(".phar/stub.php")-1); + entry.filename_len = sizeof(".phar/stub.php")-1; + entry.is_modified = 1; + entry.index = phar_stub_index; + if (SUCCESS != zend_hash_update(&archive->manifest, entry.filename, entry.filename_len, (void*)&entry, sizeof(phar_entry_info), NULL)) { + if (free_user_stub) { + efree(user_stub); + } + if (error) { + spprintf(error, 0, "unable to set stub in zip-based phar \"%s\"", archive->fname); + } return EOF; } if (free_user_stub) { efree(user_stub); } } else { - if (-1 != phar_stub_index) { - struct zip_source *source; + if (-1 == phar_stub_index) { /* this is a brand new phar, add the stub */ - if (NULL == (source = zip_source_buffer(archive->zip, newstub, sizeof(newstub) - 1, 0)) || -1 == zip_add(archive->zip, ".phar/stub.php", source)) { + entry.fp = php_stream_fopen_tmpfile(); + if (sizeof(newstub)-1 != php_stream_write(entry.fp, newstub, sizeof(newstub)-1)) { + if (error) { + spprintf(error, 0, "unable to create stub in new zip-based phar \"%s\"", archive->fname); + } + return EOF; + } + entry.uncompressed_filesize = sizeof(newstub) - 1; + entry.filename = estrndup(".phar/stub.php", sizeof(".phar/stub.php")-1); + entry.filename_len = sizeof(".phar/stub.php")-1; + entry.is_modified = 1; + entry.index = -1; + if (SUCCESS != zend_hash_add(&archive->manifest, entry.filename, entry.filename_len, (void*)&entry, sizeof(phar_entry_info), NULL)) { + php_stream_close(entry.fp); + efree(entry.filename); if (error) { spprintf(error, 0, "unable to create stub in new zip-based phar \"%s\": %s", archive->fname, zip_strerror(archive->zip)); } - zip_error_clear(archive->zip); return EOF; } } } + /* save modified files to the zip */ + zend_hash_apply(&archive->manifest, phar_zip_changed_apply TSRMLS_CC); + if (archive->zip->error.str) { + if (error) { + spprintf(error, 4096, "phar zip flush of \"%s\" failed: %s", archive->fname, zip_strerror(archive->zip)); + } + return EOF; + } + /* save zip */ if (-1 == zip_close(archive->zip)) { if (error) { @@ -3953,7 +3986,7 @@ static int phar_stream_flush(php_stream *stream TSRMLS_DC) /* {{{ */ char *error; int ret; if (stream->mode[0] == 'w' || (stream->mode[0] == 'r' && stream->mode[1] == '+')) { - ret = phar_flush(((phar_entry_data *)stream->abstract)->internal_file->phar, 0, 0, &error TSRMLS_CC); + ret = phar_flush(((phar_entry_data *)stream->abstract)->phar, 0, 0, &error TSRMLS_CC); if (error) { php_stream_wrapper_log_error(stream->wrapper, REPORT_ERRORS TSRMLS_CC, error); efree(error); @@ -4506,7 +4539,7 @@ static int phar_wrapper_rename(php_stream_wrapper *wrapper, char *url_from, char entry->fp = NULL; entry->metadata = 0; entry->link = NULL; -#if HAVE_ZIP +#if HAVE_PHAR_ZIP entry->zip = NULL; #endif @@ -4677,7 +4710,7 @@ static zend_op_array *phar_compile_file(zend_file_handle *file_handle, int type fname = zend_get_executed_filename(TSRMLS_C); fname_len = strlen(fname); - if (strstr(file_handle->filename, ".phar") && !strstr(file_handle->filename, ":\\")) { + if (strstr(file_handle->filename, ".phar") && !strstr(file_handle->filename, "://")) { if (SUCCESS == phar_open_filename(file_handle->filename, strlen(file_handle->filename), NULL, 0, 0, &phar, NULL TSRMLS_CC)) { if (phar->is_zip || phar->is_tar) { zend_file_handle f = *file_handle; diff --git a/ext/phar/phar_object.c b/ext/phar/phar_object.c index 7e9229130c..df3d25024e 100755 --- a/ext/phar/phar_object.c +++ b/ext/phar/phar_object.c @@ -1763,12 +1763,15 @@ PHP_METHOD(Phar, copy) /* new file */ newentry.fp = php_stream_temp_new(); fp = newentry.fp; - php_stream_seek(fp, 0, SEEK_SET); - if (oldentry->compressed_filesize != php_stream_copy_to_stream(oldentry->fp, fp, oldentry->compressed_filesize)) { + php_stream_seek(oldentry->fp, 0, SEEK_SET); + if (oldentry->uncompressed_filesize != php_stream_copy_to_stream(oldentry->fp, fp, oldentry->uncompressed_filesize)) { php_stream_close(fp); zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC, "file \"%s\" could not be copied to file \"%s\" in %s, copy failed", oldfile, newfile, phar_obj->arc.archive->fname); + return; } + } else { + newentry.fp = NULL; } memcpy((void *) &newentry, oldentry, sizeof(phar_entry_info)); @@ -1779,15 +1782,41 @@ PHP_METHOD(Phar, copy) } #if HAVE_PHAR_ZIP if (oldentry->is_zip) { - newentry.index = -1; + int zindex; + /* for new files, start with an empty string */ + struct zip_source *s; + if (!newentry.fp) { + if (!phar_open_jit(phar_obj->arc.archive, oldentry, NULL, &error, 0 TSRMLS_CC)) { + php_stream_close(fp); + if (error) { + zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC, + "file \"%s\" could not be copied to file \"%s\" in %s, open of source file failed: %s", oldfile, newfile, phar_obj->arc.archive->fname, error); + efree(error); + } else { + zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC, + "file \"%s\" could not be copied to file \"%s\" in %s, open of source file failed", oldfile, newfile, phar_obj->arc.archive->fname); + } + return; + } + fp = oldentry->fp; + oldentry->fp = NULL; + } + s = zip_source_buffer(phar_obj->arc.archive->zip, (void *)"", 0, 0); + if (-1 == (zindex = zip_add(phar_obj->arc.archive->zip, newfile, s))) { + zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC, + "file \"%s\" could not be copied to file \"%s\" in %s, creation of destination file failed: %s", oldfile, newfile, phar_obj->arc.archive->fname, zip_strerror(phar_obj->arc.archive->zip)); + zip_error_clear(phar_obj->arc.archive->zip); + return; + } + newentry.index = zindex; + newentry.zip = NULL; } #endif newentry.fp = fp; newentry.filename = estrndup(newfile, newfile_len); newentry.filename_len = newfile_len; - if (oldentry->is_tar) { - newentry.tar_type = oldentry->tar_type; - } + newentry.is_modified = 1; + newentry.fp_refcount = 0; phar_obj->arc.archive->is_modified = 1; zend_hash_add(&phar_obj->arc.archive->manifest, newfile, newfile_len, (void*)&newentry, sizeof(phar_entry_info), NULL); @@ -1842,7 +1871,7 @@ PHP_METHOD(Phar, offsetGet) return; } - if (!phar_get_entry_info(phar_obj->arc.archive, fname, fname_len, &error TSRMLS_CC)) { + if (!phar_get_entry_info_dir(phar_obj->arc.archive, fname, fname_len, 1, &error TSRMLS_CC)) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "Entry %s does not exist%s%s", fname, error?", ":"", error?error:""); } else { fname_len = spprintf(&fname, 0, "phar://%s/%s", phar_obj->arc.archive->fname, fname); @@ -2332,10 +2361,18 @@ PHP_METHOD(PharFileInfo, chmod) if (entry_obj->ent.entry->is_dir && (!entry_obj->ent.entry->is_tar && !entry_obj->ent.entry->is_zip)) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, \ "Phar entry is a directory, cannot chmod"); \ + return; } if (PHAR_G(readonly)) { - zend_throw_exception_ex(phar_ce_PharException, 0 TSRMLS_CC, "Cannot modify permissions for file \"%s\" write operations are prohibited", entry_obj->ent.entry->filename, entry_obj->ent.entry->phar->fname); + zend_throw_exception_ex(phar_ce_PharException, 0 TSRMLS_CC, "Cannot modify permissions for file \"%s\" in phar \"%s\", write operations are prohibited", entry_obj->ent.entry->filename, entry_obj->ent.entry->phar->fname); + return; } +#if HAVE_ZIP + if (entry_obj->ent.entry->is_zip) { + zend_throw_exception_ex(phar_ce_PharException, 0 TSRMLS_CC, "Cannot modify permissions for file \"%s\" in phar \"%s\", not supported for zip-based phars", entry_obj->ent.entry->filename, entry_obj->ent.entry->phar->fname); + return; + } +#endif if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &perms) == FAILURE) { return; } diff --git a/ext/phar/tar.c b/ext/phar/tar.c index 3a5b6cbf97..23ba450c41 100644 --- a/ext/phar/tar.c +++ b/ext/phar/tar.c @@ -156,7 +156,7 @@ int phar_open_tarfile(php_stream* fp, char *fname, int fname_len, char *alias, i size_t pos = 0, read; tar_header *hdr; php_uint32 sum1, sum2, size, old; - phar_archive_data *myphar, **retdata; + phar_archive_data *myphar; if (error) { *error = NULL; @@ -235,6 +235,8 @@ int phar_open_tarfile(php_stream* fp, char *fname, int fname_len, char *alias, i } if (entry.tar_type == TAR_DIR) { entry.is_dir = 1; + } else { + entry.is_dir = 0; } entry.link = NULL; @@ -491,12 +493,12 @@ int phar_tar_flush(phar_archive_data *archive, char *user_stub, long len, char * efree(user_stub); } } else { - if (archive->is_brandnew) { + if (!zend_hash_exists(&archive->manifest, ".phar/stub.php", sizeof(".phar/stub.php")-1)) { /* this is a brand new phar */ entry.fp = php_stream_fopen_tmpfile(); if (sizeof(newstub)-1 != php_stream_write(entry.fp, newstub, sizeof(newstub)-1)) { if (error) { - spprintf(error, 0, "unable to create stub in new phar \"%s\"", archive->fname); + spprintf(error, 0, "unable to create stub in new tar-based phar \"%s\"", archive->fname); } return EOF; } diff --git a/ext/phar/tests/033a.phpt b/ext/phar/tests/033a.phpt index 1df67f5a16..6fbc0db365 100644 --- a/ext/phar/tests/033a.phpt +++ b/ext/phar/tests/033a.phpt @@ -32,5 +32,5 @@ unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.1.phar.php ?> --EXPECTF-- bool(false) -Cannot modify permissions for file "a.php" write operations are prohibited +Cannot modify permissions for file "a.php" in phar "%s033a.1.phar.php", write operations are prohibited ===DONE=== diff --git a/ext/phar/tests/create_path_error.phpt b/ext/phar/tests/create_path_error.phpt index 1ba89d759b..d3fc035860 100755 --- a/ext/phar/tests/create_path_error.phpt +++ b/ext/phar/tests/create_path_error.phpt @@ -54,9 +54,9 @@ foreach($checks as $check) --EXPECTF-- string(5) "query" string(5) "query" -Error: file_put_contents(phar://%s//): failed to open stream: phar error: file "" cannot be empty -Error: file_put_contents(phar://%s/.): failed to open stream: phar error: file "" cannot be empty -Error: file_put_contents(phar://%s/../): failed to open stream: phar error: file "" cannot be empty -Error: file_put_contents(phar://%s/a/..): failed to open stream: phar error: file "" cannot be empty +Error: file_put_contents(phar://%s//): failed to open stream: phar error: file "" in phar "%s" cannot be empty +Error: file_put_contents(phar://%s/.): failed to open stream: phar error: file "" in phar "%s" cannot be empty +Error: file_put_contents(phar://%s/../): failed to open stream: phar error: file "" in phar "%s" cannot be empty +Error: file_put_contents(phar://%s/a/..): failed to open stream: phar error: file "" in phar "%s" cannot be empty Exception: Entry a does not exist and cannot be created: phar error: invalid path "a" contains illegal character ===DONE=== diff --git a/ext/phar/tests/tar/033a.phpt b/ext/phar/tests/tar/033a.phpt index 69bf684bbf..469dbfb94c 100644 --- a/ext/phar/tests/tar/033a.phpt +++ b/ext/phar/tests/tar/033a.phpt @@ -42,5 +42,5 @@ unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.1.phar.php ?> --EXPECTF-- bool(false) -Cannot modify permissions for file "a.php" write operations are prohibited +Cannot modify permissions for file "a.php" in phar "%s033a.1.phar.php", write operations are prohibited ===DONE=== diff --git a/ext/phar/tests/tar/open_for_write_newfile.phpt b/ext/phar/tests/tar/open_for_write_newfile.phpt index dafbab8ac7..904f245b05 100644 --- a/ext/phar/tests/tar/open_for_write_newfile.phpt +++ b/ext/phar/tests/tar/open_for_write_newfile.phpt @@ -1,5 +1,5 @@ --TEST-- -Phar: fopen a .phar for writing (new file) +Phar: fopen a .phar for writing (new file) tar-based --SKIPIF-- --INI-- diff --git a/ext/phar/tests/tar/phar_buildfromiterator5.phpt b/ext/phar/tests/tar/phar_buildfromiterator5.phpt index 3bd2cec78c..600bd2ee5c 100644 --- a/ext/phar/tests/tar/phar_buildfromiterator5.phpt +++ b/ext/phar/tests/tar/phar_buildfromiterator5.phpt @@ -1,5 +1,5 @@ --TEST-- -Phar::buildFromIterator() iterator, iterator returns non-string +Phar::buildFromIterator() iterator, iterator returns non-string tar-based --SKIPIF-- --INI-- @@ -37,7 +37,7 @@ class myIterator implements Iterator } try { chdir(dirname(__FILE__)); - $phar = new Phar(dirname(__FILE__) . '/buildfromiterator.phar'); + $phar = new Phar(dirname(__FILE__) . '/buildfromiterator.phar.tar'); var_dump($phar->buildFromIterator(new myIterator(array('a' => new stdClass)))); } catch (Exception $e) { var_dump(get_class($e)); @@ -47,7 +47,7 @@ try { ===DONE=== --CLEAN-- --EXPECTF-- diff --git a/ext/phar/tests/tar/phar_buildfromiterator6.phpt b/ext/phar/tests/tar/phar_buildfromiterator6.phpt index ae73bbd479..e891a5d065 100644 --- a/ext/phar/tests/tar/phar_buildfromiterator6.phpt +++ b/ext/phar/tests/tar/phar_buildfromiterator6.phpt @@ -1,5 +1,5 @@ --TEST-- -Phar::buildFromIterator() iterator, key is int +Phar::buildFromIterator() iterator, key is int tar-based --SKIPIF-- --INI-- @@ -37,7 +37,7 @@ class myIterator implements Iterator } try { chdir(dirname(__FILE__)); - $phar = new Phar(dirname(__FILE__) . '/buildfromiterator.phar'); + $phar = new Phar(dirname(__FILE__) . '/buildfromiterator.phar.tar'); var_dump($phar->buildFromIterator(new myIterator(array(basename(__FILE__, 'php') . 'phpt')))); } catch (Exception $e) { var_dump(get_class($e)); @@ -47,7 +47,7 @@ try { ===DONE=== --CLEAN-- --EXPECTF-- diff --git a/ext/phar/tests/tar/phar_buildfromiterator7.phpt b/ext/phar/tests/tar/phar_buildfromiterator7.phpt index 38d2e1a5f2..d64c032d71 100644 --- a/ext/phar/tests/tar/phar_buildfromiterator7.phpt +++ b/ext/phar/tests/tar/phar_buildfromiterator7.phpt @@ -1,5 +1,5 @@ --TEST-- -Phar::buildFromIterator() iterator, file can't be opened +Phar::buildFromIterator() iterator, file can't be opened tar-based --SKIPIF-- --INI-- @@ -37,7 +37,7 @@ class myIterator implements Iterator } try { chdir(dirname(__FILE__)); - $phar = new Phar(dirname(__FILE__) . '/buildfromiterator.phar'); + $phar = new Phar(dirname(__FILE__) . '/buildfromiterator.phar.tar'); var_dump($phar->buildFromIterator(new myIterator(array('a' => basename(__FILE__, 'php') . '/oopsie/there.phpt')))); } catch (Exception $e) { var_dump(get_class($e)); @@ -47,7 +47,7 @@ try { ===DONE=== --CLEAN-- --EXPECT-- diff --git a/ext/phar/tests/tar/phar_buildfromiterator9.phpt b/ext/phar/tests/tar/phar_buildfromiterator9.phpt index 0b56307545..f9deef4d9f 100644 --- a/ext/phar/tests/tar/phar_buildfromiterator9.phpt +++ b/ext/phar/tests/tar/phar_buildfromiterator9.phpt @@ -1,5 +1,5 @@ --TEST-- -Phar::buildFromIterator() iterator, 1 file resource passed in +Phar::buildFromIterator() iterator, 1 file resource passed in tar-based --SKIPIF-- --INI-- @@ -37,7 +37,7 @@ class myIterator implements Iterator } try { chdir(dirname(__FILE__)); - $phar = new Phar(dirname(__FILE__) . '/buildfromiterator.phar'); + $phar = new Phar(dirname(__FILE__) . '/buildfromiterator.phar.tar'); var_dump($phar->buildFromIterator(new myIterator(array('a' => $a = fopen(basename(__FILE__, 'php') . 'phpt', 'r'))))); fclose($a); } catch (Exception $e) { @@ -48,7 +48,7 @@ try { ===DONE=== --CLEAN-- --EXPECTF-- diff --git a/ext/phar/tests/tar/phar_stub_error.phpt b/ext/phar/tests/tar/phar_stub_error.phpt index c4cee768e8..0c4de9657a 100755 --- a/ext/phar/tests/tar/phar_stub_error.phpt +++ b/ext/phar/tests/tar/phar_stub_error.phpt @@ -1,5 +1,5 @@ --TEST-- -Phar::setStub()/getStub() +Phar::setStub()/getStub() tar-based --SKIPIF-- --INI-- diff --git a/ext/phar/tests/tar/rename.phpt b/ext/phar/tests/tar/rename.phpt index ed410a863a..e3e3dfa984 100644 --- a/ext/phar/tests/tar/rename.phpt +++ b/ext/phar/tests/tar/rename.phpt @@ -1,5 +1,5 @@ --TEST-- -Phar: rename test +Phar: rename test tar-based --SKIPIF-- --INI-- diff --git a/ext/phar/tests/zip/033.phpt b/ext/phar/tests/zip/033.phpt new file mode 100644 index 0000000000..3d0e584e64 --- /dev/null +++ b/ext/phar/tests/zip/033.phpt @@ -0,0 +1,48 @@ +--TEST-- +Phar::chmod zip-based +--SKIPIF-- + + +--INI-- +phar.readonly=0 +phar.require_hash=0 +--FILE-- +init(); +$a->addFile('a.php', ''); +$a->addFile('.phar/alias.txt', 'hio'); +$a->mkDir('test'); +$a->close(); + +try { + $a = new Phar($fname); + var_dump($a['a.php']->isExecutable()); + $a['a.php']->chmod(0777); + var_dump($a['a.php']->isExecutable()); + $a['a.php']->chmod(0666); + var_dump($a['a.php']->isExecutable()); + echo "test dir\n"; + var_dump($a['test']->isDir()); + var_dump($a['test']->isReadable()); + $a['test']->chmod(0000); + var_dump($a['test']->isReadable()); + $a['test']->chmod(0666); + var_dump($a['test']->isReadable()); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} +?> +===DONE=== +--CLEAN-- + +--EXPECTF-- +bool(false) +Cannot modify permissions for file "a.php" in phar "%s033.1.phar.php", not supported for zip-based phars +===DONE=== diff --git a/ext/phar/tests/zip/033a.phpt b/ext/phar/tests/zip/033a.phpt new file mode 100644 index 0000000000..77f1925c9e --- /dev/null +++ b/ext/phar/tests/zip/033a.phpt @@ -0,0 +1,47 @@ +--TEST-- +Phar::chmod zip-based +--SKIPIF-- + + +--INI-- +phar.readonly=1 +phar.require_hash=0 +--FILE-- +init(); +$a->addFile('a.php', ''); +$a->addFile('.phar/alias.txt', 'hio'); +$a->mkDir('test'); +$a->close(); + +try { + $a = new Phar($fname); + var_dump($a['a.php']->isExecutable()); + $a['a.php']->chmod(0777); + var_dump($a['a.php']->isExecutable()); + $a['a.php']->chmod(0666); + var_dump($a['a.php']->isExecutable()); + echo "test dir\n"; + var_dump($a['test']->isExecutable()); + $a['test']->chmod(0777); + var_dump($a['test']->isExecutable()); + $a['test']->chmod(0666); + var_dump($a['test']->isExecutable()); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} +?> +===DONE=== +--CLEAN-- + +--EXPECTF-- +bool(false) +Cannot modify permissions for file "a.php" in phar "%sa.1.phar.php", write operations are prohibited +===DONE=== diff --git a/ext/phar/tests/zip/create_new_and_modify.phpt b/ext/phar/tests/zip/create_new_and_modify.phpt new file mode 100644 index 0000000000..b81e5a779f --- /dev/null +++ b/ext/phar/tests/zip/create_new_and_modify.phpt @@ -0,0 +1,45 @@ +--TEST-- +Phar: create and modify zip-based phar +--SKIPIF-- + + +--INI-- +phar.readonly=0 +--FILE-- +isZip()); +$sig1 = md5_file($fname); + +include $pname . '/a.php'; + +file_put_contents($pname .'/a.php', "modified!\n"); +file_put_contents($pname .'/b.php', "another!\n"); + +$phar = new Phar($fname); +$sig2 = md5_file($fname); + +var_dump($sig1 != $sig2); + +include $pname . '/a.php'; +include $pname . '/b.php'; + +?> +===DONE=== +--CLEAN-- + +--EXPECTF-- +bool(true) +brand new! +bool(true) +modified! +another! +===DONE=== diff --git a/ext/phar/tests/zip/create_new_phar_b.phpt b/ext/phar/tests/zip/create_new_phar_b.phpt new file mode 100644 index 0000000000..5aec78d2b9 --- /dev/null +++ b/ext/phar/tests/zip/create_new_phar_b.phpt @@ -0,0 +1,27 @@ +--TEST-- +Phar: create a completely new zip-based phar +--SKIPIF-- + +--INI-- +phar.readonly=1 +phar.require_hash=1 +--FILE-- + + +===DONE=== +--CLEAN-- + +--EXPECTF-- + +Warning: file_put_contents(phar://%screate_new_phar_b.phar.zip/a.php): failed to open stream: phar error: write operations disabled by INI setting in %screate_new_phar_b.php on line %d + +Warning: include(phar://%screate_new_phar_b.phar.zip/a.php): failed to open stream: No such file or directory in %screate_new_phar_b.php on line %d + +Warning: include(): Failed opening 'phar://%screate_new_phar_b.phar.zip/a.php' for inclusion (include_path='%s') in %screate_new_phar_b.php on line %d + +===DONE=== diff --git a/ext/phar/tests/zip/delete.phpt b/ext/phar/tests/zip/delete.phpt new file mode 100644 index 0000000000..77ae85f909 --- /dev/null +++ b/ext/phar/tests/zip/delete.phpt @@ -0,0 +1,35 @@ +--TEST-- +Phar: delete test, zip-based phar +--SKIPIF-- + + +--INI-- +phar.readonly=0 +phar.require_hash=0 +--FILE-- +"; + +$a = new tarmaker($fname, 'none'); +$a->init(); +$a->addFile('a', 'a'); +$a->addFile('.phar/stub.php', $file); +$a->close(); + +$phar = new Phar($fname); + +echo file_get_contents($pname . '/a') . "\n"; +$phar->delete('a'); +echo file_get_contents($pname . '/a') . "\n"; +?> +--CLEAN-- + +--EXPECTF-- +a + +Warning: file_get_contents(phar://%sdelete.phar.php/a): failed to open stream: phar error: "a" is not a file in phar "%sdelete.phar.php" in %sdelete.php on line %d \ No newline at end of file diff --git a/ext/phar/tests/zip/delete_in_phar.phpt b/ext/phar/tests/zip/delete_in_phar.phpt new file mode 100644 index 0000000000..ec743b53c4 --- /dev/null +++ b/ext/phar/tests/zip/delete_in_phar.phpt @@ -0,0 +1,51 @@ +--TEST-- +Phar: delete a file within a zip-based .phar +--SKIPIF-- + + +--INI-- +phar.readonly=0 +phar.require_hash=0 +--FILE-- +init(); +$a->addFile('a.php', ''); +$a->addFile('b.php', ''); +$a->addFile('b/c.php', ''); +$a->addFile('.phar/stub.php', ''); +$a->close(); + +include $pname . '/a.php'; +include $pname . '/b.php'; +include $pname . '/b/c.php'; +unlink($pname . '/b/c.php'); +?> +===AFTER=== + + +===DONE=== +--CLEAN-- + +--EXPECTF-- +This is a +This is b +This is b/c +===AFTER=== +This is a +This is b + +Warning: include(%sdelete_in_phar.phar.php/b/c.php): failed to open stream: phar error: "b/c.php" is not a file in phar "%sdelete_in_phar.phar.php" in %sdelete_in_phar.php on line %d + +Warning: include(): Failed opening 'phar://%sdelete_in_phar.phar.php/b/c.php' for inclusion (include_path='%s') in %sdelete_in_phar.php on line %d + +===DONE=== + \ No newline at end of file diff --git a/ext/phar/tests/zip/delete_in_phar_b.phpt b/ext/phar/tests/zip/delete_in_phar_b.phpt new file mode 100644 index 0000000000..2816b10437 --- /dev/null +++ b/ext/phar/tests/zip/delete_in_phar_b.phpt @@ -0,0 +1,49 @@ +--TEST-- +Phar: delete a file within a zip-based .phar +--SKIPIF-- + + +--INI-- +phar.readonly=1 +phar.require_hash=0 +--FILE-- +init(); +$a->addFile('a.php', ''); +$a->addFile('b.php', ''); +$a->addFile('b/c.php', ''); +$a->addFile('.phar/stub.php', ''); +$a->close(); + +include $pname . '/a.php'; +include $pname . '/b.php'; +include $pname . '/b/c.php'; +unlink($pname . '/b/c.php'); +?> +===AFTER=== + + +===DONE=== +--CLEAN-- + +--EXPECTF-- +This is a +This is b +This is b/c + +Warning: unlink(): phar error: write operations disabled by INI setting in %sdelete_in_phar_b.php on line %d +===AFTER=== +This is a +This is b +This is b/c + +===DONE=== diff --git a/ext/phar/tests/zip/delete_in_phar_confirm.phpt b/ext/phar/tests/zip/delete_in_phar_confirm.phpt new file mode 100644 index 0000000000..9ffe718a85 --- /dev/null +++ b/ext/phar/tests/zip/delete_in_phar_confirm.phpt @@ -0,0 +1,53 @@ +--TEST-- +Phar: delete a file within a zip-based .phar (confirm disk file is changed) +--SKIPIF-- + + +--INI-- +phar.readonly=0 +phar.require_hash=0 +--FILE-- +init(); +$a->addFile('a.php', ''); +$a->addFile('b.php', ''); +$a->addFile('b/c.php', ''); +$a->addFile('.phar/stub.php', ''); +$a->close(); +include $pname . '/a.php'; +include $pname . '/b.php'; +include $pname . '/b/c.php'; +$md5 = md5_file($fname); +unlink($pname . '/b/c.php'); +clearstatcache(); +$md52 = md5_file($fname); +if ($md5 == $md52) echo 'file was not modified'; +?> +===AFTER=== + + +===DONE=== +--CLEAN-- + +--EXPECTF-- +This is a +This is b +This is b/c +===AFTER=== +This is a +This is b + +Warning: include(%sdelete_in_phar_confirm.phar.php/b/c.php): failed to open stream: phar error: "b/c.php" is not a file in phar "%sdelete_in_phar_confirm.phar.php" in %sdelete_in_phar_confirm.php on line %d + +Warning: include(): Failed opening 'phar://%sdelete_in_phar_confirm.phar.php/b/c.php' for inclusion (include_path='%s') in %sdelete_in_phar_confirm.php on line %d + +===DONE=== diff --git a/ext/phar/tests/zip/frontcontroller.phar.inc b/ext/phar/tests/zip/frontcontroller.phar.inc new file mode 100644 index 0000000000..241dceb57b --- /dev/null +++ b/ext/phar/tests/zip/frontcontroller.phar.inc @@ -0,0 +1,13 @@ +setStub(' diff --git a/ext/phar/tests/zip/frontcontroller.phar.zip b/ext/phar/tests/zip/frontcontroller.phar.zip new file mode 100644 index 0000000000000000000000000000000000000000..4ee905dd3ae892298fd6c4a01c17d0e5253f5e81 GIT binary patch literal 625 zcmWIWW@Zs#U|`^2Flke_So?na1y&%B8Hho2qFzBp!RZrc*ck!{sLLuy$D&R+r!heS zXpR^Vv%$!&ghqge_E~SelV{EcpEz;m`h_*?Skdg5ddyQm2&hK@h&h2cGcP5z z0_+|SU9Zp+I$-1>u-&$syTA%$m_yI8k0|5Sij=2B; literal 0 HcmV?d00001 diff --git a/ext/phar/tests/zip/frontcontroller1.phar.phpt b/ext/phar/tests/zip/frontcontroller1.phar.phpt new file mode 100644 index 0000000000..2be7ab478c --- /dev/null +++ b/ext/phar/tests/zip/frontcontroller1.phar.phpt @@ -0,0 +1,14 @@ +--TEST-- +Phar front controller other zip-based +--SKIPIF-- + +--ENV-- +SCRIPT_NAME=/frontcontroller1.phar.php/a.jpg +REQUEST_URI=/frontcontroller1.phar.php/a.jpg +--FILE_EXTERNAL-- +frontcontroller.phar.zip +--EXPECTHEADERS-- +Content-type: image/jpeg +Content-length: 3 +--EXPECT-- +hio diff --git a/ext/phar/tests/zip/frontcontroller10.phar.inc b/ext/phar/tests/zip/frontcontroller10.phar.inc new file mode 100644 index 0000000000..c973cc15d9 --- /dev/null +++ b/ext/phar/tests/zip/frontcontroller10.phar.inc @@ -0,0 +1,20 @@ +setStub(' diff --git a/ext/phar/tests/zip/frontcontroller10.phar.phpt b/ext/phar/tests/zip/frontcontroller10.phar.phpt new file mode 100644 index 0000000000..025becd670 --- /dev/null +++ b/ext/phar/tests/zip/frontcontroller10.phar.phpt @@ -0,0 +1,17 @@ +--TEST-- +Phar front controller rewrite array invalid zip-based +--SKIPIF-- + +--ENV-- +SCRIPT_NAME=/frontcontroller10.phar.php/hi +REQUEST_URI=/frontcontroller10.phar.php/hi +--FILE_EXTERNAL-- +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 diff --git a/ext/phar/tests/zip/frontcontroller10.phar.zip b/ext/phar/tests/zip/frontcontroller10.phar.zip new file mode 100644 index 0000000000000000000000000000000000000000..c37cb381fbed023f0f7a757b783f245dcab01fc3 GIT binary patch literal 471 zcmWIWW@Zs#U|`^2aB5Sxu(<;ZW#U%P|?9zA>cxXV9sLUzK6 z>;jLPj0x&`s*G}djvrfMSi)RdHcz-JSR@^xyNj7I0L2YXF-{EgfOhW(Vm=@STAx^? zUtCg}1agRP-(9XI1DT`mYr72h%y=N2A)qA8Ubn_~FW0|_zBh+**O*lORud^HuVX)V z{9#7A^oPn4&rNH7sZG5-MR{@YsetStub(' diff --git a/ext/phar/tests/zip/frontcontroller11.phar.phpt b/ext/phar/tests/zip/frontcontroller11.phar.phpt new file mode 100644 index 0000000000..789138f329 --- /dev/null +++ b/ext/phar/tests/zip/frontcontroller11.phar.phpt @@ -0,0 +1,17 @@ +--TEST-- +Phar front controller mime type extension is not a string zip-based +--SKIPIF-- + +--ENV-- +SCRIPT_NAME=/frontcontroller11.phar.php/a.php +REQUEST_URI=/frontcontroller11.phar.php/a.php +--FILE_EXTERNAL-- +frontcontroller5.phar.zip +--EXPECTHEADERS-- +Content-type: text/html +--EXPECTF-- +Fatal error: Uncaught exception 'UnexpectedValueException' with message 'Key of MIME type overrides array must be a file extension, was "0"' in %sfrontcontroller11.phar.php:2 +Stack trace: +#0 %sfrontcontroller11.phar.php(2): Phar::webPhar('whatever', 'index.php', '', Array) +#1 {main} + thrown in %sfrontcontroller11.phar.php on line 2 \ No newline at end of file diff --git a/ext/phar/tests/zip/frontcontroller11.phar.zip b/ext/phar/tests/zip/frontcontroller11.phar.zip new file mode 100644 index 0000000000000000000000000000000000000000..48e5fc678a43c94f27c859e904ffa5071c287d9d GIT binary patch literal 461 zcmWIWW@Zs#U|`^2aBfq#u(<;ZW#U%P|?9zA>cxXV9sLUzK6 z>;jLPj0x&`s*G}djvrfMSi)RdHcz-JSR@^xyNj7I0L2ZGdPY1`fOc;JVm=@STAx^? zUtCg}1agRL??J962Z@&VwnsNr1bpB$;h1PIbR{R;meoF5@8-d~PxX86?c?pyJA8)S zc=O$z7jtI?22S$XywlUSds%?s%I~WJ&+ItkdT~ocy6A`cJL0N;CNu=IZ#wEHV$*f0 z^wU!Pc;TuA>ldfqiTa*!xHjRKo#fePITgDiMIIXX>+uM@vP)z160qgC?_`sb+Wm85 z)}NUloaF<&8JQRuaEBt$6G#9ars&$xJ&w@R0%W2FLx49c8%UlB2#bNV3oybM7yy=U BlBWOw literal 0 HcmV?d00001 diff --git a/ext/phar/tests/zip/frontcontroller12.phar.inc b/ext/phar/tests/zip/frontcontroller12.phar.inc new file mode 100644 index 0000000000..77c4a1dd0e --- /dev/null +++ b/ext/phar/tests/zip/frontcontroller12.phar.inc @@ -0,0 +1,20 @@ +setStub(' diff --git a/ext/phar/tests/zip/frontcontroller12.phar.phpt b/ext/phar/tests/zip/frontcontroller12.phar.phpt new file mode 100644 index 0000000000..1b5102aa19 --- /dev/null +++ b/ext/phar/tests/zip/frontcontroller12.phar.phpt @@ -0,0 +1,17 @@ +--TEST-- +Phar front controller mime type unknown int zip-based +--SKIPIF-- + +--ENV-- +SCRIPT_NAME=/frontcontroller12.phar.php/a.php +REQUEST_URI=/frontcontroller12.phar.php/a.php +--FILE_EXTERNAL-- +frontcontroller6.phar.zip +--EXPECTHEADERS-- +Content-type: text/html +--EXPECTF-- +Fatal error: Uncaught exception 'UnexpectedValueException' with message 'Unknown mime type specifier used, only Phar::PHP, Phar::PHPS and a mime type string are allowed' in %sfrontcontroller12.phar.php:2 +Stack trace: +#0 %sfrontcontroller12.phar.php(2): Phar::webPhar('whatever', 'index.php', '', Array) +#1 {main} + thrown in %sfrontcontroller12.phar.php on line 2 \ No newline at end of file diff --git a/ext/phar/tests/zip/frontcontroller12.phar.zip b/ext/phar/tests/zip/frontcontroller12.phar.zip new file mode 100644 index 0000000000000000000000000000000000000000..c086c4d4a43a4cb647ec15b11a81e2d4dbfe3496 GIT binary patch literal 465 zcmWIWW@Zs#U|`^2aA{Mwu(<;ZW#U%P|?9zA>cxXV9sLUzK6 z>;jLPj0x&`s*G}djvrfMSi)RdHcz-JSR@^xyNj7I0L2YgEnPp(0NTA3i1~mRXnkUl zesM`@638LGy%)Kf3?y3L*LE51nejk4LqJKGb?erZ;RnxWDeo?j*6zKxkCpZA+~Nl{ z_w(MTiEoVjr4t=iEP5;dmhj8HHG*fd*qXM9`U#4u=HFnby?Akdl&S7t-#K#bT5J-P z&68FB2hIQWhf{^;mr-=f+S2kRd0dje9qLTgn?Gkvmb +--ENV-- +SCRIPT_NAME=/frontcontroller13.phar.php/a.php +REQUEST_URI=/frontcontroller13.phar.php/a.php +--FILE_EXTERNAL-- +frontcontroller7.phar.zip +--EXPECTHEADERS-- +Content-type: text/html +--EXPECTF-- +Fatal error: Uncaught exception 'UnexpectedValueException' with message 'Unknown mime type specifier used (not a string or int), only Phar::PHP, Phar::PHPS and a mime type string are allowed' in %sfrontcontroller13.phar.php:2 +Stack trace: +#0 %sfrontcontroller13.phar.php(2): Phar::webPhar('whatever', 'index.php', '', Array) +#1 {main} + thrown in %sfrontcontroller13.phar.php on line 2 \ No newline at end of file diff --git a/ext/phar/tests/zip/frontcontroller14.phar.phpt b/ext/phar/tests/zip/frontcontroller14.phar.phpt new file mode 100644 index 0000000000..7a3aaa57b2 --- /dev/null +++ b/ext/phar/tests/zip/frontcontroller14.phar.phpt @@ -0,0 +1,14 @@ +--TEST-- +Phar front controller mime type override, other zip-based +--SKIPIF-- + +--ENV-- +SCRIPT_NAME=/frontcontroller14.phar.php/a.jpg +REQUEST_URI=/frontcontroller14.phar.php/a.jpg +--FILE_EXTERNAL-- +frontcontroller8.phar.zip +--EXPECTHEADERS-- +Content-type: foo/bar +Content-length: 4 +--EXPECT-- +hio2 diff --git a/ext/phar/tests/zip/frontcontroller15.phar.phpt b/ext/phar/tests/zip/frontcontroller15.phar.phpt new file mode 100644 index 0000000000..33ac6739cd --- /dev/null +++ b/ext/phar/tests/zip/frontcontroller15.phar.phpt @@ -0,0 +1,17 @@ +--TEST-- +Phar front controller mime type override, Phar::PHPS zip-based +--SKIPIF-- + +--ENV-- +SCRIPT_NAME=/frontcontroller15.phar.php/a.php +REQUEST_URI=/frontcontroller15.phar.php/a.php +--FILE_EXTERNAL-- +frontcontroller8.phar.zip +--EXPECTHEADERS-- +Content-type: text/html +--EXPECT-- + +<?php function hio(){} + + + diff --git a/ext/phar/tests/zip/frontcontroller16.phar.phpt b/ext/phar/tests/zip/frontcontroller16.phar.phpt new file mode 100644 index 0000000000..924996b00b --- /dev/null +++ b/ext/phar/tests/zip/frontcontroller16.phar.phpt @@ -0,0 +1,14 @@ +--TEST-- +Phar front controller mime type override, Phar::PHP zip-based +--SKIPIF-- + +--ENV-- +SCRIPT_NAME=/frontcontroller16.phar.php/a.phps +REQUEST_URI=/frontcontroller16.phar.php/a.phps +--FILE_EXTERNAL-- +frontcontroller8.phar.zip +--EXPECTHEADERS-- +Content-type: text/html +--EXPECT-- +hio1 + diff --git a/ext/phar/tests/zip/frontcontroller17.phar.phpt b/ext/phar/tests/zip/frontcontroller17.phar.phpt new file mode 100644 index 0000000000..36054b8971 --- /dev/null +++ b/ext/phar/tests/zip/frontcontroller17.phar.phpt @@ -0,0 +1,15 @@ +--TEST-- +Phar front controller mime type unknown zip-based +--SKIPIF-- + +--ENV-- +SCRIPT_NAME=/frontcontroller17.phar.php/fronk.gronk +REQUEST_URI=/frontcontroller17.phar.php/fronk.gronk +--FILE_EXTERNAL-- +frontcontroller8.phar.zip +--EXPECTHEADERS-- +Content-type: application/octet-stream +Content-length: 4 +--EXPECT-- +hio3 + diff --git a/ext/phar/tests/zip/frontcontroller18.phar.phpt b/ext/phar/tests/zip/frontcontroller18.phar.phpt new file mode 100644 index 0000000000..8d9139820e --- /dev/null +++ b/ext/phar/tests/zip/frontcontroller18.phar.phpt @@ -0,0 +1,15 @@ +--TEST-- +Phar front controller $_SERVER munging failure zip-based +--SKIPIF-- + +--ENV-- +SCRIPT_NAME=/frontcontroller18.phar.php/fronk.gronk +REQUEST_URI=/frontcontroller18.phar.php/fronk.gronk +--FILE_EXTERNAL-- +frontcontroller9.phar.zip +--EXPECTF-- +Fatal error: Uncaught exception 'UnexpectedValueException' with message 'No values passed to Phar::mungServer(), expecting an array of any of these strings: PHP_SELF, REQUEST_URI, SCRIPT_FILENAME, SCRIPT_NAME' in %sfrontcontroller18.phar.php:2 +Stack trace: +#0 %sfrontcontroller18.phar.php(2): Phar::mungServer(Array) +#1 {main} + thrown in %sfrontcontroller18.phar.php on line 2 diff --git a/ext/phar/tests/zip/frontcontroller19.phar.phpt b/ext/phar/tests/zip/frontcontroller19.phar.phpt new file mode 100644 index 0000000000..8057448a60 --- /dev/null +++ b/ext/phar/tests/zip/frontcontroller19.phar.phpt @@ -0,0 +1,15 @@ +--TEST-- +Phar front controller $_SERVER munging failure 2 zip-based +--SKIPIF-- + +--ENV-- +SCRIPT_NAME=/frontcontroller19.phar.php/ +REQUEST_URI=/frontcontroller19.phar.php/ +--FILE_EXTERNAL-- +frontcontroller10.phar.zip +--EXPECTF-- +Fatal error: Uncaught exception 'UnexpectedValueException' with message 'Too many values passed to Phar::mungServer(), expecting an array of any of these strings: PHP_SELF, REQUEST_URI, SCRIPT_FILENAME, SCRIPT_NAME' in %sfrontcontroller19.phar.php:2 +Stack trace: +#0 %sfrontcontroller19.phar.php(2): Phar::mungServer(Array) +#1 {main} + thrown in %sfrontcontroller19.phar.php on line 2 diff --git a/ext/phar/tests/zip/frontcontroller2.phar.inc b/ext/phar/tests/zip/frontcontroller2.phar.inc new file mode 100644 index 0000000000..6cfa052a83 --- /dev/null +++ b/ext/phar/tests/zip/frontcontroller2.phar.inc @@ -0,0 +1,12 @@ +setStub(' diff --git a/ext/phar/tests/zip/frontcontroller2.phar.phpt b/ext/phar/tests/zip/frontcontroller2.phar.phpt new file mode 100644 index 0000000000..ac64424ecb --- /dev/null +++ b/ext/phar/tests/zip/frontcontroller2.phar.phpt @@ -0,0 +1,13 @@ +--TEST-- +Phar front controller PHP test zip-based +--SKIPIF-- + +--ENV-- +SCRIPT_NAME=/frontcontroller2.phar.php/a.php +REQUEST_URI=/frontcontroller2.phar.php/a.php +--FILE_EXTERNAL-- +frontcontroller.phar.zip +--EXPECTHEADERS-- +Content-type: text/html +--EXPECT-- +hio diff --git a/ext/phar/tests/zip/frontcontroller2.phar.zip b/ext/phar/tests/zip/frontcontroller2.phar.zip new file mode 100644 index 0000000000000000000000000000000000000000..7ef43dc000c401ff2cf07a22cd6a146116ec5031 GIT binary patch literal 531 zcmWIWW@Zs#U|`^2FmF@0So?na1y&%B8Hho2qFzBp!RZrc*ck!{sLLuy$D&R+r!heS zXpR^Vv%$!&ghqge_E~SelV{EcpEz;m`h_*?Skdgz*_V@*57bix#C$*ubV_28 zesM`@639_tGahiA@X*<`Nz31t$alP12Mpx6%;EBEI@b-NUJk~cmV92f&>5n literal 0 HcmV?d00001 diff --git a/ext/phar/tests/zip/frontcontroller20.phar.phpt b/ext/phar/tests/zip/frontcontroller20.phar.phpt new file mode 100644 index 0000000000..4b5859b33d --- /dev/null +++ b/ext/phar/tests/zip/frontcontroller20.phar.phpt @@ -0,0 +1,15 @@ +--TEST-- +Phar front controller $_SERVER munging failure 3 zip-based +--SKIPIF-- + +--ENV-- +SCRIPT_NAME=/frontcontroller20.phar.php/ +REQUEST_URI=/frontcontroller20.phar.php/ +--FILE_EXTERNAL-- +frontcontroller11.phar.zip +--EXPECTF-- +Fatal error: Uncaught exception 'UnexpectedValueException' with message 'Non-string value passed to Phar::mungServer(), expecting an array of any of these strings: PHP_SELF, REQUEST_URI, SCRIPT_FILENAME, SCRIPT_NAME' in %sfrontcontroller20.phar.php:2 +Stack trace: +#0 %sfrontcontroller20.phar.php(2): Phar::mungServer(Array) +#1 {main} + thrown in %sfrontcontroller20.phar.php on line 2 diff --git a/ext/phar/tests/zip/frontcontroller21.phar.phpt b/ext/phar/tests/zip/frontcontroller21.phar.phpt new file mode 100644 index 0000000000..cd55d9c4c6 --- /dev/null +++ b/ext/phar/tests/zip/frontcontroller21.phar.phpt @@ -0,0 +1,20 @@ +--TEST-- +Phar front controller $_SERVER munging success zip-based +--SKIPIF-- + +--ENV-- +SCRIPT_NAME=/frontcontroller21.phar.php/index.php +REQUEST_URI=/frontcontroller21.phar.php/index.php?test=hi +--FILE_EXTERNAL-- +frontcontroller12.phar.zip +--EXPECTHEADERS-- +Content-type: text/html +--EXPECTF-- +string(10) "/index.php" +string(%d) "phar://%sfrontcontroller21.phar.php/index.php" +string(%d) "phar://%sfrontcontroller21.phar.php/index.php" +string(18) "/index.php?test=hi" +string(37) "/frontcontroller21.phar.php/index.php" +string(37) "/frontcontroller21.phar.php/index.php" +string(%d) "%s/frontcontroller21.phar.php" +string(45) "/frontcontroller21.phar.php/index.php?test=hi" \ No newline at end of file diff --git a/ext/phar/tests/zip/frontcontroller3.phar.inc b/ext/phar/tests/zip/frontcontroller3.phar.inc new file mode 100644 index 0000000000..a622b81f48 --- /dev/null +++ b/ext/phar/tests/zip/frontcontroller3.phar.inc @@ -0,0 +1,12 @@ +setStub(' "a.phps")); +echo "oops did not run\n"; +var_dump($_ENV, $_SERVER); +__HALT_COMPILER();'); +?> diff --git a/ext/phar/tests/zip/frontcontroller3.phar.phpt b/ext/phar/tests/zip/frontcontroller3.phar.phpt new file mode 100644 index 0000000000..c34f4de8de --- /dev/null +++ b/ext/phar/tests/zip/frontcontroller3.phar.phpt @@ -0,0 +1,16 @@ +--TEST-- +Phar front controller phps zip-based +--SKIPIF-- + +--ENV-- +SCRIPT_NAME=/frontcontroller3.phar.php/a.phps +REQUEST_URI=/frontcontroller3.phar.php/a.phps +--FILE_EXTERNAL-- +frontcontroller.phar.zip +--EXPECTHEADERS-- +Content-type: text/html +--EXPECT-- + +<?php function hio(){} + + diff --git a/ext/phar/tests/zip/frontcontroller3.phar.zip b/ext/phar/tests/zip/frontcontroller3.phar.zip new file mode 100644 index 0000000000000000000000000000000000000000..0ca3681e0b0cbe71e5b1f13bf75afd7500e4193a GIT binary patch literal 562 zcmWIWW@Zs#U|`^2uxL}aSo?na1y&%B8Hho2qFzBp!RZrc*ck!{sLLuy$D&R+r!heS zXpR^Vv%$!&ghqge_E~SelV{EcpEz;m`h_*?SkdfQ7cuKoA5hPHAm#&Npi>fy z^ovVMlR%C#?e^w6WFW%u-SX(;i>^$r-`C2!FmZ)?Pg&P8VU`1zDd$W7{QTVo=FG;k zYd17b2|KDY+h;Gs(UYt0^{6Fr-LS~DTWvY(C~xlUrmnzR&EL%Ha+^2YWn88Ddcwvz zGp2uSxYy2CviRUnxknG?@f91b()jv;&t&4CsHGE5Sc{8_e^!0^GQj4^$1=_Htm0Fi z+6QsetStub(' true)); +echo "oops did not run\n"; +var_dump($_ENV, $_SERVER); +__HALT_COMPILER();'); +?> diff --git a/ext/phar/tests/zip/frontcontroller4.phar.phpt b/ext/phar/tests/zip/frontcontroller4.phar.phpt new file mode 100644 index 0000000000..0a6e39e2c0 --- /dev/null +++ b/ext/phar/tests/zip/frontcontroller4.phar.phpt @@ -0,0 +1,13 @@ +--TEST-- +Phar front controller index.php relocate (no /) zip-based +--SKIPIF-- + +--ENV-- +SCRIPT_NAME=/frontcontroller4.phar.php +REQUEST_URI=/frontcontroller4.phar.php +--FILE_EXTERNAL-- +frontcontroller.phar.zip +--EXPECTHEADERS-- +Status: 301 Moved Permanently +Location: /frontcontroller4.phar.php/index.php +--EXPECT-- diff --git a/ext/phar/tests/zip/frontcontroller4.phar.zip b/ext/phar/tests/zip/frontcontroller4.phar.zip new file mode 100644 index 0000000000000000000000000000000000000000..08208a5565554ed3e2147ee064c6199159031bd1 GIT binary patch literal 561 zcmWIWW@Zs#U|`^2uxwMeSo?na1y&%B8Hho2qFzBp!RZrc*ck!{sLLuy$D&R+r!heS zXpR^Vv%$!&ghqge_E~SelV{EcpEz;m`h_*?Skdg*!zyIb3)C|ki1~mR=#<1F z{o<0+B#@&_yH9f+G7w;R|F-)9r`NjsD zZ?Q>FI;C~$^T{pt2^Nv2GcF3GHO#&IZ10T4kuh(6^N39RW$=$Z<`!S#-p0m75BGSS zIb7xN{xEmR@`FDaHFoVjtRyMwDLcP$Y0#Y6JVBMBrOK~02y{IX00%1ZS~P%K6ZL@Mi>?Jda1mAnfVBWasTf@kdY~fo^Z=QtK^)-C R3W_rZ79hL^q+J<7JOIE>lDhx^ literal 0 HcmV?d00001 diff --git a/ext/phar/tests/zip/frontcontroller5.phar.inc b/ext/phar/tests/zip/frontcontroller5.phar.inc new file mode 100644 index 0000000000..931fa975e1 --- /dev/null +++ b/ext/phar/tests/zip/frontcontroller5.phar.inc @@ -0,0 +1,12 @@ +setStub(' "oops")); +echo "oops did not run\n"; +var_dump($_ENV, $_SERVER); +__HALT_COMPILER();'); +?> diff --git a/ext/phar/tests/zip/frontcontroller5.phar.phpt b/ext/phar/tests/zip/frontcontroller5.phar.phpt new file mode 100644 index 0000000000..1e69240a0a --- /dev/null +++ b/ext/phar/tests/zip/frontcontroller5.phar.phpt @@ -0,0 +1,13 @@ +--TEST-- +Phar front controller index.php relocate zip-based +--SKIPIF-- + +--ENV-- +SCRIPT_NAME=/frontcontroller5.phar.php/ +REQUEST_URI=/frontcontroller5.phar.php/ +--FILE_EXTERNAL-- +frontcontroller.phar.zip +--EXPECTHEADERS-- +Status: 301 Moved Permanently +Location: /frontcontroller5.phar.php/index.php +--EXPECT-- diff --git a/ext/phar/tests/zip/frontcontroller5.phar.zip b/ext/phar/tests/zip/frontcontroller5.phar.zip new file mode 100644 index 0000000000000000000000000000000000000000..0ab0472101505cd2e2107ff9bf5dfa1f23d700c0 GIT binary patch literal 554 zcmWIWW@Zs#U|`^2uxeAcSo?na1y&%B8Hho2qFzBp!RZrc*ck!{sLLuy$D&R+r!heS zXpR^Vv%$!&ghqge_E~SelV{EcpEz;m`h_*?SkdfAd?{$x2GlbFi1~mR=#<1F z{o<0+B#@(2yZyNjDabgyuj`WE)O@Jp+-7?h4%XFeNBtUih{))O&W^7A-IMqJVD;+U z4UDE?M_0}A{m$H!zS_-rW{3BIy_cWuJrO82y=@_j=;B`!RM(g{?B&<@(R6;6_&471 zyVM+cMYZzs84EpKS6()r;Pk0D+DUPJ%$ArZ-lq<)+jsKs(alP!#2R16%<(vEI@b- JNZT=jcmS`#j!ggn literal 0 HcmV?d00001 diff --git a/ext/phar/tests/zip/frontcontroller6.phar.inc b/ext/phar/tests/zip/frontcontroller6.phar.inc new file mode 100644 index 0000000000..3b551f268d --- /dev/null +++ b/ext/phar/tests/zip/frontcontroller6.phar.inc @@ -0,0 +1,12 @@ +setStub(' 100)); +echo "oops did not run\n"; +var_dump($_ENV, $_SERVER); +__HALT_COMPILER();'); +?> diff --git a/ext/phar/tests/zip/frontcontroller6.phar.phpt b/ext/phar/tests/zip/frontcontroller6.phar.phpt new file mode 100644 index 0000000000..4f3435be22 --- /dev/null +++ b/ext/phar/tests/zip/frontcontroller6.phar.phpt @@ -0,0 +1,20 @@ +--TEST-- +Phar front controller 404 zip-based +--SKIPIF-- + +--ENV-- +SCRIPT_NAME=/frontcontroller6.phar.php/notfound.php +REQUEST_URI=/frontcontroller6.phar.php/notfound.php +--FILE_EXTERNAL-- +frontcontroller.phar.zip +--EXPECTHEADERS-- +Status: 404 Not Found +--EXPECT-- + + + File Not Found<title> + </head> + <body> + <h1>404 - File /notfound.php Not Found</h1> + </body> +</html> \ No newline at end of file diff --git a/ext/phar/tests/zip/frontcontroller6.phar.zip b/ext/phar/tests/zip/frontcontroller6.phar.zip new file mode 100644 index 0000000000000000000000000000000000000000..bf98255fe9a9d85b6c41c16d9eb104d9a5e93cd7 GIT binary patch literal 559 zcmWIWW@Zs#U|`^2uxeAcSo?na1y&%B8Hho2qFzBp!RZrc*ck!{sLLuy$D&R+r!heS zXpR^Vv%$<O-n>!&ghqge_E~SelV{EcpEz;m`h_*?SkdfItm6{v2I`pv#C$*ubV_28 zesM`@639`a-QHY>3`7{dTONIU(Ur^f)wa-X4~K<WotLHx1POa6swsY3ynXw-w1l)^ zR$-6i6rHZf^7;i9(v~kg-On&oFaMIh)unsK#alcnJ)gWcZoZ_DQ@-KcXA|AdIw}4a zwH3{;L@n$cWbPhL^i-2<m5OgvYl^+aBUG5YC$(m0i^aRwyDehQpIw<YXW3K!0B=Sn z1_s=L2y{CV00$}YS~P%K6ZL?hi>?JdXc1NffVBX_s2E)jdXOUY^Z=Qt0UY4X3W_lX N79hL^q@5W-JOFUbjG6!d literal 0 HcmV?d00001 diff --git a/ext/phar/tests/zip/frontcontroller7.phar.inc b/ext/phar/tests/zip/frontcontroller7.phar.inc new file mode 100644 index 0000000000..42c10bc739 --- /dev/null +++ b/ext/phar/tests/zip/frontcontroller7.phar.inc @@ -0,0 +1,12 @@ +<?php +@unlink(dirname(__FILE__) . '/frontcontroller7.phar.zip'); +$a = new Phar(dirname(__FILE__) . '/frontcontroller7.phar.zip'); +$a['a.php'] = 'hio'; +$a['a.jpg'] = 'hio'; +$a['a.phps'] = '<?php function hio(){}'; +$a->setStub('<?php +Phar::webPhar("whatever", "index.php", null, array("blah" => null)); +echo "oops did not run\n"; +var_dump($_ENV, $_SERVER); +__HALT_COMPILER();'); +?> diff --git a/ext/phar/tests/zip/frontcontroller7.phar.phpt b/ext/phar/tests/zip/frontcontroller7.phar.phpt new file mode 100644 index 0000000000..2ce206fc21 --- /dev/null +++ b/ext/phar/tests/zip/frontcontroller7.phar.phpt @@ -0,0 +1,13 @@ +--TEST-- +Phar front controller alternate index file zip-based +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +--ENV-- +SCRIPT_NAME=/frontcontroller7.phar.php/ +REQUEST_URI=/frontcontroller7.phar.php/ +--FILE_EXTERNAL-- +frontcontroller2.phar.zip +--EXPECTHEADERS-- +Status: 301 Moved Permanently +Location: /frontcontroller7.phar.php/a.php +--EXPECT-- diff --git a/ext/phar/tests/zip/frontcontroller7.phar.zip b/ext/phar/tests/zip/frontcontroller7.phar.zip new file mode 100644 index 0000000000000000000000000000000000000000..02fc3e27b6970ab9ce9db3c5ee8f2436574ac197 GIT binary patch literal 559 zcmWIWW@Zs#U|`^2ux?YgSo?na1y&%B8Hho2qFzBp!RZrc*ck!{sLLuy$D&R+r!heS zXpR^Vv%$<O-n>!&ghqge_E~SelV{EcpEz;m`h_*?SkdfQI7zOe8>nY85c2^s&?$*U z`o$%sNgzkbcAw@tWFW%&{cqRlrQIw|@)v$Ns4NKB8uHSMBU9KzQBBco?Z3TO@6Jp- zS0(OqB1<_r@XW5?yiJ=YE}mE7!e(Ky^!{qqr~|6mk|!jdwkM=7b-a=Df7&IZ%X>dI z+-nzK;n?_D`N$JFzSB9A0#|(DQ4#-h$>_w<UUS|2Y10Lc*OrR6zusvVx<_%#AEp3r zMkWRZ+<^#mI}!i~De+n~fLasvfT4@71wCjHRs?{x0K=#lT@QMYBJ}hCnWzCA;LQq( PF$NYOyauG589_V%5WSN@ literal 0 HcmV?d00001 diff --git a/ext/phar/tests/zip/frontcontroller8.phar.inc b/ext/phar/tests/zip/frontcontroller8.phar.inc new file mode 100644 index 0000000000..e04ac414e9 --- /dev/null +++ b/ext/phar/tests/zip/frontcontroller8.phar.inc @@ -0,0 +1,13 @@ +<?php +@unlink(dirname(__FILE__) . '/frontcontroller8.phar.zip'); +$a = new Phar(dirname(__FILE__) . '/frontcontroller8.phar.zip'); +$a['a.phps'] = 'hio1'; +$a['a.jpg'] = 'hio2'; +$a['a.php'] = '<?php function hio(){}'; +$a['fronk.gronk'] = 'hio3'; +$a->setStub('<?php +Phar::webPhar("whatever", "index.php", null, array("jpg" => "foo/bar", "phps" => Phar::PHP, "php" => Phar::PHPS)); +echo "oops did not run\n"; +var_dump($_ENV, $_SERVER); +__HALT_COMPILER();'); +?> diff --git a/ext/phar/tests/zip/frontcontroller8.phar.phpt b/ext/phar/tests/zip/frontcontroller8.phar.phpt new file mode 100644 index 0000000000..dd806b6cf0 --- /dev/null +++ b/ext/phar/tests/zip/frontcontroller8.phar.phpt @@ -0,0 +1,20 @@ +--TEST-- +Phar front controller no index file 404 zip-based +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +--ENV-- +SCRIPT_NAME=/frontcontroller8.phar.php/ +REQUEST_URI=/frontcontroller8.phar.php/ +--FILE_EXTERNAL-- +frontcontroller3.phar.zip +--EXPECTHEADERS-- +Status: 404 Not Found +--EXPECT-- +<html> + <head> + <title>File Not Found<title> + </head> + <body> + <h1>404 - File index.php Not Found</h1> + </body> +</html> \ No newline at end of file diff --git a/ext/phar/tests/zip/frontcontroller8.phar.zip b/ext/phar/tests/zip/frontcontroller8.phar.zip new file mode 100644 index 0000000000000000000000000000000000000000..41952ce745a92d3d6b64db7e8f5c6e0cc8c6d4a3 GIT binary patch literal 684 zcmWIWW@Zs#U|`^2uxV4b;BC*=W&`qAfEYw4>J?-Z6rVnE#+-#A07d2YYe}16Dp|oQ zvkKBd3YpLp3g<K?NB|Xx0Wm}&(8$dj^-pL7cxa#X);oFTeDH}AXRcpZvyK%_tKzfN zqcA(Tf!foG^7FFw(m^E1CN?zXRhNT{=K+-+1Y$lQ2D&}5NWZwGGzsL3(4JWCCIgAq z_kTt84|B7wtbW_v(b#zP!Urvh&1=(cm^};s`+HhkY5BRs#pklJmwfC<G3#>={Oi=< zcGAj_qg%;g>!U||3npo=%AdtCW9u8?1<NZHBJvsTZjB4enKbvBUxA&9=FEro+J_82 z9`Vg`h?*@{an|uAU(Wh<T&njD=sf*<n#JzuawDesVix*^@4}`m+x^Dr`*UT>6bt@C zPq+iT8JQRua7P5tJ4gT$E$DjCqXeNr3&>2=14a<K7WBwLXbA>u0frm87W7C#Xz2qo lk)jA)BYN~8H0}j5Q6nqBn-vuCzy!m}z|Y9Q&<?~53;@IHtpxx8 literal 0 HcmV?d00001 diff --git a/ext/phar/tests/zip/frontcontroller9.phar.inc b/ext/phar/tests/zip/frontcontroller9.phar.inc new file mode 100644 index 0000000000..50440451f7 --- /dev/null +++ b/ext/phar/tests/zip/frontcontroller9.phar.inc @@ -0,0 +1,14 @@ +<?php +@unlink(dirname(__FILE__) . '/frontcontroller9.phar.zip'); +$a = new Phar(dirname(__FILE__) . '/frontcontroller9.phar.zip'); +$a['a.phps'] = 'hio1'; +$a['a.jpg'] = 'hio2'; +$a['a.php'] = '<?php function hio(){}'; +$a['fronk.gronk'] = 'hio3'; +$a->setStub('<?php +Phar::mungServer(array()); +Phar::webPhar("whatever", "index.php", null, array("jpg" => "foo/bar", "phps" => Phar::PHP, "php" => Phar::PHPS)); +echo "oops did not run\n"; +var_dump($_ENV, $_SERVER); +__HALT_COMPILER();'); +?> diff --git a/ext/phar/tests/zip/frontcontroller9.phar.phpt b/ext/phar/tests/zip/frontcontroller9.phar.phpt new file mode 100644 index 0000000000..70dbaa05ad --- /dev/null +++ b/ext/phar/tests/zip/frontcontroller9.phar.phpt @@ -0,0 +1,16 @@ +--TEST-- +Phar front controller rewrite array zip-based +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +--ENV-- +SCRIPT_NAME=/frontcontroller9.phar.php/hi +REQUEST_URI=/frontcontroller9.phar.php/hi +--FILE_EXTERNAL-- +frontcontroller3.phar.zip +--EXPECTHEADERS-- +Content-type: text/html +--EXPECT-- +<code><span style="color: #000000"> +<span style="color: #0000BB"><?php </span><span style="color: #007700">function </span><span style="color: #0000BB">hio</span><span style="color: #007700">(){}</span> +</span> +</code> \ No newline at end of file diff --git a/ext/phar/tests/zip/frontcontroller9.phar.zip b/ext/phar/tests/zip/frontcontroller9.phar.zip new file mode 100644 index 0000000000000000000000000000000000000000..d3f4ff84042959c0b7ba0a17bbac03781cd212a8 GIT binary patch literal 697 zcmWIWW@Zs#U|`^2ux(Sf;BC*=W&`qAfEYw4>J?-Z6rVnE#+-#A07d2YYe}16Dp|oQ zvkKBd3YpLp3g<K?NB|Xx0Wm}&(8$dj^-pL7cxa#X);oFTeDH}AXRcpZvyK%_tKzfN zqcA(Tf!foG^7FFw(m^E1CN?zXH{6oGuLdf+1H^nl40L;9k$!PWX%fg6p}nX1nhXS7 zzt<dHk{BqosQQCovWJ1AYC^<JlcQk=9BxmU{%<eqogK3+zu%d8Hg4*vF7H*g>tDJ~ zEV3==U3u+Gv+VKzuFB_^GcMk^MAn?Gh%vP3<M&fv&MN)dRhGDN;dCv5obrZwLF<aG zPP=8N?~v&^T+#SnXKvglcTGmml~D<z%!<|*_U_<*63u+I<!kRDGfusk+-9E5D%?Vs zl~in8%!~HSdmJpHa^vIv0B=Sn1_s=*0`waafW#5H9`yJ@XwU*O6ZL?xg{}oXrVv_! z!CHWUh^_@ah7el%fJ~(LLf42MR|t)JflSnx3-D$Ir2=5;VP)WFWMG&A#0(4on5?pB literal 0 HcmV?d00001 diff --git a/ext/phar/tests/zip/make_invalid_tar.php.inc b/ext/phar/tests/zip/make_invalid_tar.php.inc new file mode 100644 index 0000000000..cec8ef7793 --- /dev/null +++ b/ext/phar/tests/zip/make_invalid_tar.php.inc @@ -0,0 +1,12 @@ +<?php +include dirname(__FILE__) . '/tarmaker.php.inc'; +class corrupter extends tarmaker { +function close() +{ + parent::close(); + $fp = fopen($this->path, 'r+b'); + fseek($fp, 20); + fwrite($fp, 'oopsie'); + fclose($fp); +} +} \ No newline at end of file diff --git a/ext/phar/tests/zip/open_for_write_existing.phpt b/ext/phar/tests/zip/open_for_write_existing.phpt new file mode 100644 index 0000000000..6e677e7451 --- /dev/null +++ b/ext/phar/tests/zip/open_for_write_existing.phpt @@ -0,0 +1,38 @@ +--TEST-- +Phar: fopen a .phar for writing (existing file) zip-based +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +<?php if (!extension_loaded("zip")) die("skip"); ?> +--INI-- +phar.readonly=0 +phar.require_hash=0 +--FILE-- +<?php +include dirname(__FILE__) . '/tarmaker.php.inc'; +$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip.php'; +$pname = 'phar://' . $fname; +$a = new tarmaker($fname, 'none'); +$a->init(); +$a->addFile('.phar/stub.php', "<?php __HALT_COMPILER(); ?>"); + +$files = array(); +$files['a.php'] = '<?php echo "This is a\n"; ?>'; +$files['b.php'] = '<?php echo "This is b\n"; ?>'; +$files['b/c.php'] = '<?php echo "This is b/c\n"; ?>'; +foreach ($files as $n => $file) { +$a->addFile($n, $file); +} +$a->close(); + +$fp = fopen($pname . '/b/c.php', 'wb'); +fwrite($fp, 'extra'); +fclose($fp); +include $pname . '/b/c.php'; +?> + +===DONE=== +--CLEAN-- +<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.zip.php'); ?> +--EXPECT-- +extra +===DONE=== diff --git a/ext/phar/tests/zip/open_for_write_existing_b.phpt b/ext/phar/tests/zip/open_for_write_existing_b.phpt new file mode 100755 index 0000000000..e3eb75ccc4 --- /dev/null +++ b/ext/phar/tests/zip/open_for_write_existing_b.phpt @@ -0,0 +1,49 @@ +--TEST-- +Phar: fopen a .phar for writing (existing file) zip-based +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +<?php if (!extension_loaded("zip")) die("skip"); ?> +--INI-- +phar.readonly=1 +phar.require_hash=0 +--FILE-- +<?php +include dirname(__FILE__) . '/tarmaker.php.inc'; +$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip.php'; +$pname = 'phar://' . $fname; +$a = new tarmaker($fname, 'none'); +$a->init(); +$a->addFile('.phar/stub.php', "<?php __HALT_COMPILER(); ?>"); + +$files = array(); +$files['a.php'] = '<?php echo "This is a\n"; ?>'; +$files['b.php'] = '<?php echo "This is b\n"; ?>'; +$files['b/c.php'] = '<?php echo "This is b/c\n"; ?>'; +foreach ($files as $n => $file) { +$a->addFile($n, $file); +} +$a->close(); + +function err_handler($errno, $errstr, $errfile, $errline) { + echo "Catchable fatal error: $errstr in $errfile on line $errline\n"; +} + +set_error_handler("err_handler", E_RECOVERABLE_ERROR); + +$fp = fopen($pname . '/b/c.php', 'wb'); +fwrite($fp, 'extra'); +fclose($fp); +include $pname . '/b/c.php'; +?> +===DONE=== +--CLEAN-- +<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.zip.php'); ?> +--EXPECTF-- + +Warning: fopen(phar://%sopen_for_write_existing_b.phar.zip.php/b/c.php): failed to open stream: phar error: write operations disabled by INI setting in %sopen_for_write_existing_b.php on line %d + +Warning: fwrite(): supplied argument is not a valid stream resource in %spen_for_write_existing_b.php on line %d + +Warning: fclose(): supplied argument is not a valid stream resource in %spen_for_write_existing_b.php on line %d +This is b/c +===DONE=== \ No newline at end of file diff --git a/ext/phar/tests/zip/open_for_write_existing_c.phpt b/ext/phar/tests/zip/open_for_write_existing_c.phpt new file mode 100755 index 0000000000..308c74d348 --- /dev/null +++ b/ext/phar/tests/zip/open_for_write_existing_c.phpt @@ -0,0 +1,43 @@ +--TEST-- +Phar: fopen a .phar for writing (existing file) tar-based +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +<?php if (!extension_loaded("zip")) die("skip"); ?> +--INI-- +phar.readonly=1 +phar.require_hash=0 +--FILE-- +<?php +include dirname(__FILE__) . '/tarmaker.php.inc'; +$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip.php'; +$pname = 'phar://' . $fname; +$a = new tarmaker($fname, 'none'); +$a->init(); +$a->addFile('.phar/stub.php', "<?php __HALT_COMPILER(); ?>"); + +$files = array(); +$files['a.php'] = '<?php echo "This is a\n"; ?>'; +$files['b.php'] = '<?php echo "This is b\n"; ?>'; +$files['b/c.php'] = '<?php echo "This is b/c\n"; ?>'; +foreach ($files as $n => $file) { +$a->addFile($n, $file); +} +$a->close(); + +$fp = fopen($pname . '/b/c.php', 'wb'); +fwrite($fp, 'extra'); +fclose($fp); +include $pname . '/b/c.php'; +?> +===DONE=== +--CLEAN-- +<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.zip.php'); ?> +--EXPECTF-- + +Warning: fopen(phar://%sopen_for_write_existing_c.phar.zip.php/b/c.php): failed to open stream: phar error: write operations disabled by INI setting in %sopen_for_write_existing_c.php on line %d + +Warning: fwrite(): supplied argument is not a valid stream resource in %sopen_for_write_existing_c.php on line %d + +Warning: fclose(): supplied argument is not a valid stream resource in %sopen_for_write_existing_c.php on line %d +This is b/c +===DONE=== \ No newline at end of file diff --git a/ext/phar/tests/zip/open_for_write_newfile.phpt b/ext/phar/tests/zip/open_for_write_newfile.phpt new file mode 100644 index 0000000000..e30ae54636 --- /dev/null +++ b/ext/phar/tests/zip/open_for_write_newfile.phpt @@ -0,0 +1,40 @@ +--TEST-- +Phar: fopen a .phar for writing (new file) zip-based +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +<?php if (!extension_loaded("zip")) die("skip"); ?> +--INI-- +phar.readonly=0 +phar.require_hash=0 +--FILE-- +<?php +include dirname(__FILE__) . '/tarmaker.php.inc'; +$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip.php'; +$pname = 'phar://' . $fname; +$a = new tarmaker($fname, 'none'); +$a->init(); +$a->addFile('.phar/stub.php', "<?php __HALT_COMPILER(); ?>"); + +$files = array(); +$files['a.php'] = '<?php echo "This is a\n"; ?>'; +$files['b.php'] = '<?php echo "This is b\n"; ?>'; +$files['b/c.php'] = '<?php echo "This is b/c\n"; ?>'; +foreach ($files as $n => $file) { +$a->addFile($n, $file); +} +$a->close(); + +$fp = fopen($pname . '/b/new.php', 'wb'); +fwrite($fp, 'extra'); +fclose($fp); +include $pname . '/b/c.php'; +include $pname . '/b/new.php'; +?> + +===DONE=== +--CLEAN-- +<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.zip.php'); ?> +--EXPECT-- +This is b/c +extra +===DONE=== diff --git a/ext/phar/tests/zip/open_for_write_newfile_b.phpt b/ext/phar/tests/zip/open_for_write_newfile_b.phpt new file mode 100755 index 0000000000..854917eb4b --- /dev/null +++ b/ext/phar/tests/zip/open_for_write_newfile_b.phpt @@ -0,0 +1,56 @@ +--TEST-- +Phar: fopen a .phar for writing (new file) zip-based +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +<?php if (!extension_loaded("zip")) die("skip"); ?> +--INI-- +phar.readonly=1 +phar.require_hash=0 +--FILE-- +<?php +include dirname(__FILE__) . '/tarmaker.php.inc'; +$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip.php'; +$pname = 'phar://' . $fname; +$a = new tarmaker($fname, 'none'); +$a->init(); +$a->addFile('.phar/stub.php', "<?php __HALT_COMPILER(); ?>"); + +$files = array(); +$files['a.php'] = '<?php echo "This is a\n"; ?>'; +$files['b.php'] = '<?php echo "This is b\n"; ?>'; +$files['b/c.php'] = '<?php echo "This is b/c\n"; ?>'; +foreach ($files as $n => $file) { +$a->addFile($n, $file); +} +$a->close(); + +function err_handler($errno, $errstr, $errfile, $errline) { + echo "Catchable fatal error: $errstr in $errfile on line $errline\n"; +} + +set_error_handler("err_handler", E_RECOVERABLE_ERROR); + +$fp = fopen($pname . '/b/new.php', 'wb'); +fwrite($fp, 'extra'); +fclose($fp); +include $pname . '/b/c.php'; +include $pname . '/b/new.php'; +?> + +===DONE=== +--CLEAN-- +<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.zip.php'); ?> +--EXPECTF-- + +Warning: fopen(phar://%sopen_for_write_newfile_b.phar.zip.php/b/new.php): failed to open stream: phar error: write operations disabled by INI setting in %sopen_for_write_newfile_b.php on line %d + +Warning: fwrite(): supplied argument is not a valid stream resource in %sopen_for_write_newfile_b.php on line %d + +Warning: fclose(): supplied argument is not a valid stream resource in %sopen_for_write_newfile_b.php on line %d +This is b/c + +Warning: include(phar://%sopen_for_write_newfile_b.phar.zip.php/b/new.php): failed to open stream: phar error: "b/new.php" is not a file in phar "%sopen_for_write_newfile_b.phar.zip.php" in %sopen_for_write_newfile_b.php on line %d + +Warning: include(): Failed opening 'phar://%sopen_for_write_newfile_b.phar.zip.php/b/new.php' for inclusion (include_path='%s') in %sopen_for_write_newfile_b.php on line %d + +===DONE=== diff --git a/ext/phar/tests/zip/open_for_write_newfile_c.phpt b/ext/phar/tests/zip/open_for_write_newfile_c.phpt new file mode 100755 index 0000000000..01b5871511 --- /dev/null +++ b/ext/phar/tests/zip/open_for_write_newfile_c.phpt @@ -0,0 +1,50 @@ +--TEST-- +Phar: fopen a .phar for writing (new file) zip-based +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +<?php if (!extension_loaded("zip")) die("skip"); ?> +--INI-- +phar.readonly=1 +phar.require_hash=0 +--FILE-- +<?php +include dirname(__FILE__) . '/tarmaker.php.inc'; +$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip.php'; +$pname = 'phar://' . $fname; +$a = new tarmaker($fname, 'none'); +$a->init(); +$a->addFile('.phar/stub.php', "<?php __HALT_COMPILER(); ?>"); + +$files = array(); +$files['a.php'] = '<?php echo "This is a\n"; ?>'; +$files['b.php'] = '<?php echo "This is b\n"; ?>'; +$files['b/c.php'] = '<?php echo "This is b/c\n"; ?>'; +foreach ($files as $n => $file) { +$a->addFile($n, $file); +} +$a->close(); + +$fp = fopen($pname . '/b/new.php', 'wb'); +fwrite($fp, 'extra'); +fclose($fp); +include $pname . '/b/c.php'; +include $pname . '/b/new.php'; +?> + +===DONE=== +--CLEAN-- +<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.zip.php'); ?> +--EXPECTF-- + +Warning: fopen(phar://%sopen_for_write_newfile_c.phar.zip.php/b/new.php): failed to open stream: phar error: write operations disabled by INI setting in %sopen_for_write_newfile_c.php on line %d + +Warning: fwrite(): supplied argument is not a valid stream resource in %sopen_for_write_newfile_c.php on line %d + +Warning: fclose(): supplied argument is not a valid stream resource in %sopen_for_write_newfile_c.php on line %d +This is b/c + +Warning: include(phar://%sopen_for_write_newfile_c.phar.zip.php/b/new.php): failed to open stream: phar error: "b/new.php" is not a file in phar "%sopen_for_write_newfile_c.phar.zip.php" in %sopen_for_write_newfile_c.php on line %d + +Warning: include(): Failed opening 'phar://%sopen_for_write_newfile_c.phar.zip.php/b/new.php' for inclusion (include_path='%s') in %sopen_for_write_newfile_c.php on line %d + +===DONE=== \ No newline at end of file diff --git a/ext/phar/tests/zip/phar_begin_setstub_commit.phpt b/ext/phar/tests/zip/phar_begin_setstub_commit.phpt new file mode 100755 index 0000000000..66c0134634 --- /dev/null +++ b/ext/phar/tests/zip/phar_begin_setstub_commit.phpt @@ -0,0 +1,51 @@ +--TEST-- +Phar::startBuffering()/setStub()/stopBuffering() zip-based +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +--INI-- +phar.readonly=0 +--FILE-- +<?php +$p = new Phar(dirname(__FILE__) . '/brandnewphar.phar.zip', 0, 'brandnewphar.phar'); +var_dump($p->isZip()); +//var_dump($p->getStub()); +var_dump($p->isBuffering()); +$p->startBuffering(); +var_dump($p->isBuffering()); +$p['a.php'] = '<?php var_dump("Hello");'; +$p->setStub('<?php var_dump("First"); Phar::mapPhar("brandnewphar.phar"); __HALT_COMPILER(); ?>'); +include 'phar://brandnewphar.phar/a.php'; +var_dump($p->getStub()); +$p['b.php'] = '<?php var_dump("World");'; +$p->setStub('<?php var_dump("Second"); Phar::mapPhar("brandnewphar.phar"); __HALT_COMPILER();'); +include 'phar://brandnewphar.phar/b.php'; +var_dump($p->getStub()); +$p->stopBuffering(); +echo "===COMMIT===\n"; +var_dump($p->isBuffering()); +include 'phar://brandnewphar.phar/a.php'; +include 'phar://brandnewphar.phar/b.php'; +var_dump($p->getStub()); +?> +===DONE=== +--CLEAN-- +<?php +unlink(dirname(__FILE__) . '/brandnewphar.phar.zip'); +?> +--EXPECT-- +bool(true) +bool(true) +bool(false) +string(5) "Hello" +string(84) "<?php var_dump("First"); Phar::mapPhar("brandnewphar.phar"); __HALT_COMPILER(); ?> +" +string(5) "World" +string(85) "<?php var_dump("Second"); Phar::mapPhar("brandnewphar.phar"); __HALT_COMPILER(); ?> +" +===COMMIT=== +bool(true) +string(5) "Hello" +string(5) "World" +string(85) "<?php var_dump("Second"); Phar::mapPhar("brandnewphar.phar"); __HALT_COMPILER(); ?> +" +===DONE=== \ No newline at end of file diff --git a/ext/phar/tests/zip/phar_buildfromiterator4.phpt b/ext/phar/tests/zip/phar_buildfromiterator4.phpt new file mode 100644 index 0000000000..fe402b6b45 --- /dev/null +++ b/ext/phar/tests/zip/phar_buildfromiterator4.phpt @@ -0,0 +1,66 @@ +--TEST-- +Phar::buildFromIterator() iterator, 1 file passed in zip-based +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +--INI-- +phar.require_hash=0 +phar.readonly=0 +--FILE-- +<?php +class myIterator implements Iterator +{ + var $a; + function __construct(array $a) + { + $this->a = $a; + } + function next() { + echo "next\n"; + return next($this->a); + } + function current() { + echo "current\n"; + return current($this->a); + } + function key() { + echo "key\n"; + return key($this->a); + } + function valid() { + echo "valid\n"; + return current($this->a); + } + function rewind() { + echo "rewind\n"; + return reset($this->a); + } +} +try { + chdir(dirname(__FILE__)); + $phar = new Phar(dirname(__FILE__) . '/buildfromiterator.phar.zip'); + var_dump($phar->buildFromIterator(new myIterator(array('a' => basename(__FILE__, 'php') . 'phpt')))); + var_dump($phar->isZip()); +} catch (Exception $e) { + var_dump(get_class($e)); + echo $e->getMessage() . "\n"; +} +?> +===DONE=== +--CLEAN-- +<?php +unlink(dirname(__FILE__) . '/buildfromiterator.phar.zip'); +__HALT_COMPILER(); +?> +--EXPECTF-- +rewind +valid +current +key +next +valid +array(1) { + ["a"]=> + string(%d) "%sphar_buildfromiterator4.phpt" +} +bool(true) +===DONE=== diff --git a/ext/phar/tests/zip/phar_buildfromiterator5.phpt b/ext/phar/tests/zip/phar_buildfromiterator5.phpt new file mode 100644 index 0000000000..450ada100d --- /dev/null +++ b/ext/phar/tests/zip/phar_buildfromiterator5.phpt @@ -0,0 +1,59 @@ +--TEST-- +Phar::buildFromIterator() iterator, iterator returns non-string zip-based +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +--INI-- +phar.require_hash=0 +phar.readonly=0 +--FILE-- +<?php +class myIterator implements Iterator +{ + var $a; + function __construct(array $a) + { + $this->a = $a; + } + function next() { + echo "next\n"; + return next($this->a); + } + function current() { + echo "current\n"; + return current($this->a); + } + function key() { + echo "key\n"; + return key($this->a); + } + function valid() { + echo "valid\n"; + return current($this->a); + } + function rewind() { + echo "rewind\n"; + return reset($this->a); + } +} +try { + chdir(dirname(__FILE__)); + $phar = new Phar(dirname(__FILE__) . '/buildfromiterator.phar.zip'); + var_dump($phar->buildFromIterator(new myIterator(array('a' => new stdClass)))); +} catch (Exception $e) { + var_dump(get_class($e)); + echo $e->getMessage() . "\n"; +} +?> +===DONE=== +--CLEAN-- +<?php +unlink(dirname(__FILE__) . '/buildfromiterator.phar.zip'); +__HALT_COMPILER(); +?> +--EXPECTF-- +rewind +valid +current +string(24) "UnexpectedValueException" +Iterator myIterator returned an invalid value (must return a string) +===DONE=== diff --git a/ext/phar/tests/zip/phar_buildfromiterator6.phpt b/ext/phar/tests/zip/phar_buildfromiterator6.phpt new file mode 100644 index 0000000000..2dfb04dbf0 --- /dev/null +++ b/ext/phar/tests/zip/phar_buildfromiterator6.phpt @@ -0,0 +1,60 @@ +--TEST-- +Phar::buildFromIterator() iterator, key is int zip-based +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +--INI-- +phar.require_hash=0 +phar.readonly=0 +--FILE-- +<?php +class myIterator implements Iterator +{ + var $a; + function __construct(array $a) + { + $this->a = $a; + } + function next() { + echo "next\n"; + return next($this->a); + } + function current() { + echo "current\n"; + return current($this->a); + } + function key() { + echo "key\n"; + return key($this->a); + } + function valid() { + echo "valid\n"; + return current($this->a); + } + function rewind() { + echo "rewind\n"; + return reset($this->a); + } +} +try { + chdir(dirname(__FILE__)); + $phar = new Phar(dirname(__FILE__) . '/buildfromiterator.phar.zip'); + var_dump($phar->buildFromIterator(new myIterator(array(basename(__FILE__, 'php') . 'phpt')))); +} catch (Exception $e) { + var_dump(get_class($e)); + echo $e->getMessage() . "\n"; +} +?> +===DONE=== +--CLEAN-- +<?php +unlink(dirname(__FILE__) . '/buildfromiterator.phar.zip'); +__HALT_COMPILER(); +?> +--EXPECTF-- +rewind +valid +current +key +string(24) "UnexpectedValueException" +Iterator myIterator returned an invalid key (must return a string) +===DONE=== diff --git a/ext/phar/tests/zip/phar_buildfromiterator7.phpt b/ext/phar/tests/zip/phar_buildfromiterator7.phpt new file mode 100644 index 0000000000..16ba6d61b9 --- /dev/null +++ b/ext/phar/tests/zip/phar_buildfromiterator7.phpt @@ -0,0 +1,60 @@ +--TEST-- +Phar::buildFromIterator() iterator, file can't be opened zip-based +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +--INI-- +phar.require_hash=0 +phar.readonly=0 +--FILE-- +<?php +class myIterator implements Iterator +{ + var $a; + function __construct(array $a) + { + $this->a = $a; + } + function next() { + echo "next\n"; + return next($this->a); + } + function current() { + echo "current\n"; + return current($this->a); + } + function key() { + echo "key\n"; + return key($this->a); + } + function valid() { + echo "valid\n"; + return current($this->a); + } + function rewind() { + echo "rewind\n"; + return reset($this->a); + } +} +try { + chdir(dirname(__FILE__)); + $phar = new Phar(dirname(__FILE__) . '/buildfromiterator.phar.zip'); + var_dump($phar->buildFromIterator(new myIterator(array('a' => basename(__FILE__, 'php') . '/oopsie/there.phpt')))); +} catch (Exception $e) { + var_dump(get_class($e)); + echo $e->getMessage() . "\n"; +} +?> +===DONE=== +--CLEAN-- +<?php +unlink(dirname(__FILE__) . '/buildfromiterator.phar.zip'); +__HALT_COMPILER(); +?> +--EXPECT-- +rewind +valid +current +key +string(24) "UnexpectedValueException" +Iterator myIterator returned a file that could not be opened "phar_buildfromiterator7./oopsie/there.phpt" +===DONE=== diff --git a/ext/phar/tests/zip/phar_buildfromiterator8.phpt b/ext/phar/tests/zip/phar_buildfromiterator8.phpt new file mode 100644 index 0000000000..0222dc8b4f --- /dev/null +++ b/ext/phar/tests/zip/phar_buildfromiterator8.phpt @@ -0,0 +1,73 @@ +--TEST-- +Phar::buildFromIterator() iterator, SplFileInfo as current zip-based +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +--INI-- +phar.readonly=0 +--FILE-- +<?php +try { + chdir(dirname(__FILE__)); + $phar = new Phar(dirname(__FILE__) . '/buildfromiterator.phar.zip'); + $a = $phar->buildFromIterator(new RegexIterator(new DirectoryIterator('.'), '/^frontcontroller\d{0,2}\.phar\.phpt\\z|^\.\\z|^\.\.\\z/'), dirname(__FILE__) . DIRECTORY_SEPARATOR); + asort($a); + var_dump($a); + var_dump($phar->isZip()); +} catch (Exception $e) { + var_dump(get_class($e)); + echo $e->getMessage() . "\n"; +} +?> +===DONE=== +--CLEAN-- +<?php +unlink(dirname(__FILE__) . '/buildfromiterator.phar.zip'); +__HALT_COMPILER(); +?> +--EXPECTF-- +array(21) { + ["frontcontroller1.phar.phpt"]=> + string(%d) "%sfrontcontroller1.phar.phpt" + ["frontcontroller10.phar.phpt"]=> + string(%d) "%sfrontcontroller10.phar.phpt" + ["frontcontroller11.phar.phpt"]=> + string(%d) "%sfrontcontroller11.phar.phpt" + ["frontcontroller12.phar.phpt"]=> + string(%d) "%sfrontcontroller12.phar.phpt" + ["frontcontroller13.phar.phpt"]=> + string(%d) "%sfrontcontroller13.phar.phpt" + ["frontcontroller14.phar.phpt"]=> + string(%d) "%sfrontcontroller14.phar.phpt" + ["frontcontroller15.phar.phpt"]=> + string(%d) "%sfrontcontroller15.phar.phpt" + ["frontcontroller16.phar.phpt"]=> + string(%d) "%sfrontcontroller16.phar.phpt" + ["frontcontroller17.phar.phpt"]=> + string(%d) "%sfrontcontroller17.phar.phpt" + ["frontcontroller18.phar.phpt"]=> + string(%d) "%sfrontcontroller18.phar.phpt" + ["frontcontroller19.phar.phpt"]=> + string(%d) "%sfrontcontroller19.phar.phpt" + ["frontcontroller2.phar.phpt"]=> + string(%d) "%sfrontcontroller2.phar.phpt" + ["frontcontroller20.phar.phpt"]=> + string(%d) "%sfrontcontroller20.phar.phpt" + ["frontcontroller21.phar.phpt"]=> + string(%d) "%sfrontcontroller21.phar.phpt" + ["frontcontroller3.phar.phpt"]=> + string(%d) "%sfrontcontroller3.phar.phpt" + ["frontcontroller4.phar.phpt"]=> + string(%d) "%sfrontcontroller4.phar.phpt" + ["frontcontroller5.phar.phpt"]=> + string(%d) "%sfrontcontroller5.phar.phpt" + ["frontcontroller6.phar.phpt"]=> + string(%d) "%sfrontcontroller6.phar.phpt" + ["frontcontroller7.phar.phpt"]=> + string(%d) "%sfrontcontroller7.phar.phpt" + ["frontcontroller8.phar.phpt"]=> + string(%d) "%sfrontcontroller8.phar.phpt" + ["frontcontroller9.phar.phpt"]=> + string(%d) "%sfrontcontroller9.phar.phpt" +} +bool(true) +===DONE=== diff --git a/ext/phar/tests/zip/phar_buildfromiterator9.phpt b/ext/phar/tests/zip/phar_buildfromiterator9.phpt new file mode 100644 index 0000000000..0b56307545 --- /dev/null +++ b/ext/phar/tests/zip/phar_buildfromiterator9.phpt @@ -0,0 +1,65 @@ +--TEST-- +Phar::buildFromIterator() iterator, 1 file resource passed in +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +--INI-- +phar.require_hash=0 +phar.readonly=0 +--FILE-- +<?php +class myIterator implements Iterator +{ + var $a; + function __construct(array $a) + { + $this->a = $a; + } + function next() { + echo "next\n"; + return next($this->a); + } + function current() { + echo "current\n"; + return current($this->a); + } + function key() { + echo "key\n"; + return key($this->a); + } + function valid() { + echo "valid\n"; + return current($this->a); + } + function rewind() { + echo "rewind\n"; + return reset($this->a); + } +} +try { + chdir(dirname(__FILE__)); + $phar = new Phar(dirname(__FILE__) . '/buildfromiterator.phar'); + var_dump($phar->buildFromIterator(new myIterator(array('a' => $a = fopen(basename(__FILE__, 'php') . 'phpt', 'r'))))); + fclose($a); +} catch (Exception $e) { + var_dump(get_class($e)); + echo $e->getMessage() . "\n"; +} +?> +===DONE=== +--CLEAN-- +<?php +unlink(dirname(__FILE__) . '/buildfromiterator.phar'); +__HALT_COMPILER(); +?> +--EXPECTF-- +rewind +valid +current +key +next +valid +array(1) { + ["a"]=> + string(%d) "[stream]" +} +===DONE=== diff --git a/ext/phar/tests/zip/phar_commitwrite.phpt b/ext/phar/tests/zip/phar_commitwrite.phpt new file mode 100644 index 0000000000..b954e60069 --- /dev/null +++ b/ext/phar/tests/zip/phar_commitwrite.phpt @@ -0,0 +1,44 @@ +--TEST-- +Phar::setStub()/stopBuffering() tar-based +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +--INI-- +phar.require_hash=0 +phar.readonly=0 +--FILE-- +<?php +$p = new Phar(dirname(__FILE__) . '/brandnewphar.phar.zip', 0, 'brandnewphar.phar'); +$p['file1.txt'] = 'hi'; +$p->stopBuffering(); +var_dump($p->getStub()); +$p->setStub("<?php +function __autoload(\$class) +{ + include 'phar://' . str_replace('_', '/', \$class); +} +Phar::mapPhar('brandnewphar.phar'); +include 'phar://brandnewphar.phar/startup.php'; +__HALT_COMPILER(); +?>"); +var_dump($p->getStub()); +var_dump($p->isZip()); +?> +===DONE=== +--CLEAN-- +<?php +unlink(dirname(__FILE__) . '/brandnewphar.phar.zip'); +?> +--EXPECT-- +string(60) "<?php // zip-based phar archive stub file +__HALT_COMPILER();" +string(200) "<?php +function __autoload($class) +{ + include 'phar://' . str_replace('_', '/', $class); +} +Phar::mapPhar('brandnewphar.phar'); +include 'phar://brandnewphar.phar/startup.php'; +__HALT_COMPILER(); ?> +" +bool(true) +===DONE=== \ No newline at end of file diff --git a/ext/phar/tests/zip/phar_copy.phpt b/ext/phar/tests/zip/phar_copy.phpt new file mode 100644 index 0000000000..d5a234fdc5 --- /dev/null +++ b/ext/phar/tests/zip/phar_copy.phpt @@ -0,0 +1,56 @@ +--TEST-- +Phar: copy() zip-based +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +<?php if (!extension_loaded("spl")) die("skip SPL not available"); ?> +<?php if (!extension_loaded("zlib")) die("skip zlib not available"); ?> +--INI-- +phar.readonly=0 +phar.require_hash=1 +--FILE-- +<?php + +$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip.php'; +$fname2 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '2.phar.php'; + +$pname = 'phar://'.$fname; +$iname = '/file.txt'; +$ename = '/error/'; + +$p = new Phar($fname); + +try +{ + $p['a'] = 'hi'; + $p->startBuffering(); + $p->copy('a', 'b'); + echo file_get_contents($p['b']->getPathName()); + $p->copy('b', 'c'); + $p->stopBuffering(); + echo file_get_contents($p['c']->getPathName()); + copy($fname, $fname2); + var_dump($p->isZip()); + $p->copy('a', $ename); +} +catch(Exception $e) +{ + echo $e->getMessage() . "\n"; +} +ini_set('phar.readonly',1); +$p2 = new Phar($fname2); +var_dump($p2->isZip()); +echo "\n"; +echo 'a: ' , file_get_contents($p2['a']->getPathName()); +echo 'b: ' ,file_get_contents($p2['b']->getPathName()); +echo 'c: ' ,file_get_contents($p2['c']->getPathName()); +?> +===DONE=== +--CLEAN-- +<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.zip.php'); ?> +<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '2.phar.php'); ?> +--EXPECTF-- +hihibool(true) +file "/error/" contains invalid characters empty directory, cannot be copied from "a" in phar %s +bool(true) + +a: hib: hic: hi===DONE=== \ No newline at end of file diff --git a/ext/phar/tests/zip/phar_magic.phpt b/ext/phar/tests/zip/phar_magic.phpt new file mode 100644 index 0000000000..7afcc3a56c --- /dev/null +++ b/ext/phar/tests/zip/phar_magic.phpt @@ -0,0 +1,32 @@ +--TEST-- +Phar: include/fopen magic zip-based +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +--INI-- +phar.require_hash=0 +phar.readonly=0 +--FILE-- +<?php +$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.zip.php'; +$p = new Phar($fname); +var_dump($p->isZip()); +$p['a'] = '<?php include "b/c.php";' . "\n"; +$p['b/c.php'] = '<?php echo "in b\n";$a = fopen("a", "r", true);echo stream_get_contents($a);fclose($a);include dirname(__FILE__) . "/../d";'; +$p['d'] = "in d\n"; +$p->setStub('<?php +include "phar://" . __FILE__ . "/a"; +__HALT_COMPILER();'); +include $fname; +?> +===DONE=== +--CLEAN-- +<?php +unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.zip.php'); +__HALT_COMPILER(); +?> +--EXPECTF-- +bool(true) +in b +<?php include "b/c.php"; +in d +===DONE=== diff --git a/ext/phar/tests/zip/phar_setalias.phpt b/ext/phar/tests/zip/phar_setalias.phpt new file mode 100644 index 0000000000..ecd969a1dd --- /dev/null +++ b/ext/phar/tests/zip/phar_setalias.phpt @@ -0,0 +1,42 @@ +--TEST-- +Phar::setAlias() zip-based +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +--INI-- +phar.require_hash=0 +phar.readonly=0 +--FILE-- +<?php +include dirname(__FILE__) . '/tarmaker.php.inc'; +$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php'; +$pname = 'phar://' . $fname; +$a = new tarmaker($fname, 'none'); +$a->init(); +$a->addFile('.phar/stub.php', '<?php echo "first stub\n"; __HALT_COMPILER(); ?>'); + +$files = array(); +$files['a'] = 'a'; +$files['b'] = 'b'; +$files['c'] = 'c'; +$files['.phar/alias.txt'] = 'hio'; +foreach ($files as $n => $file) { +$a->addFile($n, $file); +} +$a->close(); + +$phar = new Phar($fname); +echo $phar->getAlias() . "\n"; +$phar->setAlias('test'); +echo $phar->getAlias() . "\n"; +?> +===DONE=== +--CLEAN-- +<?php +unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); +unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phartmp.php'); +__HALT_COMPILER(); +?> +--EXPECT-- +hio +test +===DONE=== diff --git a/ext/phar/tests/zip/phar_setalias2.phpt b/ext/phar/tests/zip/phar_setalias2.phpt new file mode 100644 index 0000000000..0fc6430fd5 --- /dev/null +++ b/ext/phar/tests/zip/phar_setalias2.phpt @@ -0,0 +1,51 @@ +--TEST-- +Phar::setAlias() error zip-based +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +<?php if (!extension_loaded("zip")) die("skip"); ?> +--INI-- +phar.require_hash=0 +phar.readonly=0 +--FILE-- +<?php +include dirname(__FILE__) . '/tarmaker.php.inc'; +$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php'; +$pname = 'phar://' . $fname; +$a = new tarmaker($fname, 'none'); +$a->init(); +$a->addFile('.phar/stub.php', '<?php echo "first stub\n"; __HALT_COMPILER(); ?>'); + +$files = array(); +$files['a'] = 'a'; +$files['b'] = 'b'; +$files['c'] = 'c'; +$files['.phar/alias.txt'] = 'hio'; +foreach ($files as $n => $file) { +$a->addFile($n, $file); +} +$a->close(); + +$phar = new Phar($fname); +echo $phar->getAlias() . "\n"; +$phar->setAlias('test'); +echo $phar->getAlias() . "\n"; +$phar = new Phar(dirname(__FILE__) . '/notphar.phar'); +try { + $phar->setAlias('test'); +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} +?> +===DONE=== +--CLEAN-- +<?php +unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); +unlink(dirname(__FILE__) . '/notphar.phar'); +unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phartmp.php'); +__HALT_COMPILER(); +?> +--EXPECTF-- +hio +test +alias "test" is already used for archive "%sphar_setalias2.phar.php" and cannot be used for other archives +===DONE=== diff --git a/ext/phar/tests/zip/phar_stub_error.phpt b/ext/phar/tests/zip/phar_stub_error.phpt new file mode 100755 index 0000000000..6a1d3fc199 --- /dev/null +++ b/ext/phar/tests/zip/phar_stub_error.phpt @@ -0,0 +1,62 @@ +--TEST-- +Phar::setStub()/getStub() zip-based +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +<?php if (!extension_loaded("zip")) die("skip"); ?> +--INI-- +phar.require_hash=0 +phar.readonly=0 +--FILE-- +<?php +include dirname(__FILE__) . '/tarmaker.php.inc'; +$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php'; +$pname = 'phar://' . $fname; +$a = new tarmaker($fname, 'none'); +$a->init(); +$a->addFile('.phar/stub.php', $stub = '<?php echo "first stub\n"; __HALT_COMPILER(); ?>'); + +$files = array(); +$files['a'] = 'a'; +$files['.phar/alias.txt'] = 'hio'; +foreach ($files as $n => $file) { +$a->addFile($n, $file); +} +$a->close(); + +$phar = new Phar($fname); +var_dump($stub); +var_dump($phar->getStub()); +var_dump($phar->getStub() == $stub); + +$newstub = '<?php echo "second stub\n"; _x_HALT_COMPILER(); ?>'; +try +{ + $phar->setStub($newstub); +} +catch(exception $e) +{ + echo 'Exception: ' . $e->getMessage() . "\n"; +} +var_dump($phar->getStub()); +var_dump($phar->getStub() == $stub); +$phar->stopBuffering(); +var_dump($phar->getStub()); +var_dump($phar->getStub() == $stub); + +?> +===DONE=== +--CLEAN-- +<?php +unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); +__HALT_COMPILER(); +?> +--EXPECTF-- +string(48) "<?php echo "first stub\n"; __HALT_COMPILER(); ?>" +string(48) "<?php echo "first stub\n"; __HALT_COMPILER(); ?>" +bool(true) +Exception: illegal stub for zip-based phar "%sphar_stub_error.phar.php" +string(48) "<?php echo "first stub\n"; __HALT_COMPILER(); ?>" +bool(true) +string(48) "<?php echo "first stub\n"; __HALT_COMPILER(); ?>" +bool(true) +===DONE=== diff --git a/ext/phar/tests/zip/refcount1.phpt b/ext/phar/tests/zip/refcount1.phpt new file mode 100644 index 0000000000..b70fb5e146 --- /dev/null +++ b/ext/phar/tests/zip/refcount1.phpt @@ -0,0 +1,71 @@ +--TEST-- +Phar: test that refcounting avoids problems with deleting a file zip-based +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +<?php if (!extension_loaded("spl")) die("skip SPL not available"); ?> +<?php if (version_compare(PHP_VERSION, "5.3", "<")) die("skip requires 5.3 or later"); ?> +<?php if (!extension_loaded("zip")) die("skip"); ?> +--INI-- +phar.readonly=0 +phar.require_hash=0 +--FILE-- +<?php +include dirname(__FILE__) . '/tarmaker.php.inc'; +$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php'; +$pname = 'phar://' . $fname; +$a = new tarmaker($fname, 'none'); +$a->init(); +$a->addFile('.phar/stub.php', "<?php __HALT_COMPILER(); ?>"); + + +$files = array(); +$files['a.php'] = '<?php echo "This is a\n"; ?>'; +$files['b.php'] = '<?php echo "This is b\n"; ?>'; +$files['b/c.php'] = '<?php echo "This is b/c\n"; ?>'; +$files['.phar/alias.txt'] = 'hio'; +foreach ($files as $n => $file) { +$a->addFile($n, $file); +} +$a->close(); + +$fp = fopen($pname . '/b/c.php', 'wb'); +fwrite($fp, "extra"); +fclose($fp); +echo "===CLOSE===\n"; +$p = new Phar($fname); +$b = fopen($pname . '/b/c.php', 'rb'); +$a = $p['b/c.php']; +var_dump($a); +var_dump(fread($b, 20)); +rewind($b); +echo "===UNLINK===\n"; +unlink($pname . '/b/c.php'); +var_dump($a); +var_dump(fread($b, 20)); +include $pname . '/b/c.php'; +?> + +===DONE=== +--CLEAN-- +<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?> +--EXPECTF-- +===CLOSE=== +object(PharFileInfo)#%d (2) { + ["pathName":"SplFileInfo":private]=> + string(%d) "phar://%srefcount1.phar.php/b" + ["fileName":"SplFileInfo":private]=> + string(%d) "phar://%srefcount1.phar.php/b/c.php" +} +string(5) "extra" +===UNLINK=== + +Warning: unlink(): phar error: "b/c.php" in phar "%srefcount1.phar.php", has open file pointers, cannot unlink in %srefcount1.php on line %d +object(PharFileInfo)#%d (2) { + ["pathName":"SplFileInfo":private]=> + string(%d) "phar://%srefcount1.phar.php/b" + ["fileName":"SplFileInfo":private]=> + string(%s) "phar://%srefcount1.phar.php/b/c.php" +} +string(5) "extra" +extra +===DONE=== diff --git a/ext/phar/tests/zip/refcount1_5_2.phpt b/ext/phar/tests/zip/refcount1_5_2.phpt new file mode 100755 index 0000000000..5098ccd90e --- /dev/null +++ b/ext/phar/tests/zip/refcount1_5_2.phpt @@ -0,0 +1,63 @@ +--TEST-- +Phar: test that refcounting avoids problems with deleting a file zip-based +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +<?php if (!extension_loaded("spl")) die("skip SPL not available"); ?> +<?php if (version_compare(PHP_VERSION, "5.2", ">")) die("skip requires 5.2 or earlier"); ?> +<?php if (!extension_loaded("zip")) die("skip"); ?> +--INI-- +phar.readonly=0 +phar.require_hash=0 +--FILE-- +<?php +include dirname(__FILE__) . '/tarmaker.php.inc'; +$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php'; +$pname = 'phar://' . $fname; +$a = new tarmaker($fname, 'none'); +$a->init(); +$a->addFile('.phar/stub.php', "<?php __HALT_COMPILER(); ?>"); + + +$files = array(); +$files['a.php'] = '<?php echo "This is a\n"; ?>'; +$files['b.php'] = '<?php echo "This is b\n"; ?>'; +$files['b/c.php'] = '<?php echo "This is b/c\n"; ?>'; +$files['.phar/alias.txt'] = 'hio'; +foreach ($files as $n => $file) { +$a->addFile($n, $file); +} +$a->close(); + +$fp = fopen($pname . '/b/c.php', 'wb'); +fwrite($fp, "extra"); +fclose($fp); +echo "===CLOSE===\n"; +$p = new Phar($fname); +$b = fopen($pname . '/b/c.php', 'rb'); +$a = $p['b/c.php']; +var_dump($a); +var_dump(fread($b, 20)); +rewind($b); +echo "===UNLINK===\n"; +unlink($pname . '/b/c.php'); +var_dump($a); +var_dump(fread($b, 20)); +include $pname . '/b/c.php'; +?> + +===DONE=== +--CLEAN-- +<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?> +--EXPECTF-- +===CLOSE=== +object(PharFileInfo)#%d (0) { +} +string(5) "extra" +===UNLINK=== + +Warning: unlink(): phar error: "b/c.php" in phar "%sefcount1.phar.php", has open file pointers, cannot unlink in %sefcount1.php on line %d +object(PharFileInfo)#%d (0) { +} +string(5) "extra" +extra +===DONE=== diff --git a/ext/phar/tests/zip/rename.phpt b/ext/phar/tests/zip/rename.phpt new file mode 100644 index 0000000000..9a97f266ac --- /dev/null +++ b/ext/phar/tests/zip/rename.phpt @@ -0,0 +1,40 @@ +--TEST-- +Phar: rename test zip-based +--SKIPIF-- +<?php if (!extension_loaded("phar")) die("skip"); ?> +<?php if (!extension_loaded("zip")) die("skip"); ?> +--INI-- +phar.readonly=0 +phar.require_hash=0 +--FILE-- +<?php +include dirname(__FILE__) . '/tarmaker.php.inc'; +$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php'; +$pname = 'phar://' . $fname; +$a = new tarmaker($fname, 'none'); +$a->init(); +$a->addFile('.phar/stub.php', "<?php +Phar::mapPhar('hio'); +__HALT_COMPILER(); ?>"); + +$files = array(); +$files['a'] = 'a'; +foreach ($files as $n => $file) { +$a->addFile($n, $file); +} +$a->close(); + +include $fname; + +echo file_get_contents($pname . '/a') . "\n"; +rename($pname . '/a', $pname . '/b'); +echo file_get_contents($pname . '/b') . "\n"; +echo file_get_contents($pname . '/a') . "\n"; +?> +--CLEAN-- +<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?> +--EXPECTF-- +a +a + +Warning: file_get_contents(phar://%srename.phar.php/a): failed to open stream: phar error: "a" is not a file in phar "%srename.phar.php" in %srename.php on line %d \ No newline at end of file diff --git a/ext/phar/tests/zip/tarmaker.php.inc b/ext/phar/tests/zip/tarmaker.php.inc new file mode 100644 index 0000000000..ad05ae64c3 --- /dev/null +++ b/ext/phar/tests/zip/tarmaker.php.inc @@ -0,0 +1,70 @@ +<?php +// stolen from PEAR2_Pyrus_Developer_Creator_Zip by Greg Beaver, the original author, for use in unit tests +class tarmaker +{ + /** + * Path to archive file + * + * @var string + */ + protected $archive; + /** + * @var ZIPArchive + */ + protected $zip; + protected $path; + function __construct($path) + { + if (!class_exists('ZIPArchive')) { + throw new Exception( + 'Zip extension is not available'); + } + $this->path = $path; + } + + /** + * save a file inside this package + * @param string relative path within the package + * @param string|resource file contents or open file handle + */ + function addFile($path, $fileOrStream) + { + if (is_resource($fileOrStream)) { + $this->zip->addFromString($path, stream_get_contents($fileOrStream)); + } else { + $this->zip->addFromString($path, $fileOrStream); + } + } + + /** + * Initialize the package creator + */ + function init() + { + $this->zip = new ZipArchive; + if (true !== $this->zip->open($this->path, ZIPARCHIVE::CREATE)) { + throw new Exception( + 'Cannot open ZIP archive ' . $this->path + ); + } + } + + /** + * Create an internal directory, creating parent directories as needed + * + * This is a no-op for the tar creator + * @param string $dir + */ + function mkdir($dir) + { + $this->zip->addEmptyDir($dir); + } + + /** + * Finish saving the package + */ + function close() + { + $this->zip->close(); + } +} \ No newline at end of file -- 2.40.0