From: Greg Beaver Date: Sat, 5 Jan 2008 06:14:43 +0000 (+0000) Subject: new tests, fix mime type overrides (all web front controller primary features are... X-Git-Tag: RELEASE_2_0_0a1~1019 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=efc22a372682a215e49a61ccbbb1a877480ceff1;p=php new tests, fix mime type overrides (all web front controller primary features are now tested and working for regular phar files) --- diff --git a/ext/phar/phar_object.c b/ext/phar/phar_object.c index 0849559a9b..fb863c91bf 100755 --- a/ext/phar/phar_object.c +++ b/ext/phar/phar_object.c @@ -541,17 +541,22 @@ PHP_METHOD(Phar, webPhar) /* set up user overrides */ #define PHAR_SET_USER_MIME(ret) \ - mime.mime = Z_STRVAL_P(val); \ - mime.len = Z_STRLEN_P(val); \ + if (Z_TYPE_PP(val) == IS_LONG) { \ + mime.mime = ""; \ + mime.len = 0; \ + } else { \ + mime.mime = Z_STRVAL_PP(val); \ + mime.len = Z_STRLEN_PP(val); \ + } \ mime.type = ret; \ - zend_hash_update(&mimetypes, key, keylen, (void *)&mime, sizeof(phar_mime_type), NULL); + zend_hash_update(&mimetypes, key, keylen-1, (void *)&mime, sizeof(phar_mime_type), NULL); if (mimeoverride) { if (!zend_hash_num_elements(Z_ARRVAL_P(mimeoverride))) { goto no_mimes; } for (zend_hash_internal_pointer_reset(Z_ARRVAL_P(mimeoverride)); SUCCESS == zend_hash_has_more_elements(Z_ARRVAL_P(mimeoverride)); zend_hash_move_forward(Z_ARRVAL_P(mimeoverride))) { - zval *val; + zval **val; char *key; uint keylen; ulong intkey; @@ -571,10 +576,10 @@ PHP_METHOD(Phar, webPhar) #endif RETURN_FALSE; } - switch (Z_TYPE_P(val)) { + switch (Z_TYPE_PP(val)) { case IS_LONG : - if (Z_LVAL_P(val) == PHAR_MIME_PHP || Z_LVAL_P(val) == PHAR_MIME_PHPS) { - PHAR_SET_USER_MIME(Z_LVAL_P(val)) + if (Z_LVAL_PP(val) == PHAR_MIME_PHP || Z_LVAL_PP(val) == PHAR_MIME_PHPS) { + PHAR_SET_USER_MIME(Z_LVAL_PP(val)) } else { zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC, "Unknown mime type specifier used, only Phar::PHP, Phar::PHPS and a mime type string are allowed"); phar_entry_delref(phar TSRMLS_CC); @@ -588,7 +593,7 @@ PHP_METHOD(Phar, webPhar) PHAR_SET_USER_MIME(PHAR_MIME_OTHER) break; default : - zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC, "Unknown mime type specifier used, only Phar::PHP, Phar::PHPS and a mime type string are allowed"); + zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC, "Unknown mime type specifier used (not a string or int), only Phar::PHP, Phar::PHPS and a mime type string are allowed"); phar_entry_delref(phar TSRMLS_CC); #ifdef PHP_WIN32 efree(fname); diff --git a/ext/phar/tests/frontcontroller11.phpt b/ext/phar/tests/frontcontroller11.phpt index 5160d71273..3da89977cb 100644 --- a/ext/phar/tests/frontcontroller11.phpt +++ b/ext/phar/tests/frontcontroller11.phpt @@ -1,5 +1,5 @@ --TEST-- -Phar front controller rewrite array invalid +Phar front controller mime type extension is not a string --SKIPIF-- --ENV-- diff --git a/ext/phar/tests/frontcontroller12.phpt b/ext/phar/tests/frontcontroller12.phpt new file mode 100644 index 0000000000..8054fa53a3 --- /dev/null +++ b/ext/phar/tests/frontcontroller12.phpt @@ -0,0 +1,17 @@ +--TEST-- +Phar front controller mime type unknown int +--SKIPIF-- + +--ENV-- +SCRIPT_NAME=/frontcontroller12.php/a.php +REQUEST_URI=/frontcontroller12.php/a.php +--FILE_EXTERNAL-- +frontcontroller6.phar +--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.php:2 +Stack trace: +#0 %sfrontcontroller12.php(2): Phar::webPhar('whatever', 'index.php', '', Array) +#1 {main} + thrown in %sfrontcontroller12.php on line 2 \ No newline at end of file diff --git a/ext/phar/tests/frontcontroller13.phpt b/ext/phar/tests/frontcontroller13.phpt new file mode 100644 index 0000000000..eb3c01ff9a --- /dev/null +++ b/ext/phar/tests/frontcontroller13.phpt @@ -0,0 +1,17 @@ +--TEST-- +Phar front controller mime type not string/int +--SKIPIF-- + +--ENV-- +SCRIPT_NAME=/frontcontroller13.php/a.php +REQUEST_URI=/frontcontroller13.php/a.php +--FILE_EXTERNAL-- +frontcontroller7.phar +--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.php:2 +Stack trace: +#0 %sfrontcontroller13.php(2): Phar::webPhar('whatever', 'index.php', '', Array) +#1 {main} + thrown in %sfrontcontroller13.php on line 2 \ No newline at end of file diff --git a/ext/phar/tests/frontcontroller14.phpt b/ext/phar/tests/frontcontroller14.phpt new file mode 100644 index 0000000000..0a7e61aff0 --- /dev/null +++ b/ext/phar/tests/frontcontroller14.phpt @@ -0,0 +1,14 @@ +--TEST-- +Phar front controller mime type override, other +--SKIPIF-- + +--ENV-- +SCRIPT_NAME=/frontcontroller14.php/a.jpg +REQUEST_URI=/frontcontroller14.php/a.jpg +--FILE_EXTERNAL-- +frontcontroller8.phar +--EXPECTHEADERS-- +Content-type: foo/bar +Content-length: 4 +--EXPECT-- +hio2 diff --git a/ext/phar/tests/frontcontroller15.phpt b/ext/phar/tests/frontcontroller15.phpt new file mode 100644 index 0000000000..21fb069231 --- /dev/null +++ b/ext/phar/tests/frontcontroller15.phpt @@ -0,0 +1,17 @@ +--TEST-- +Phar front controller mime type override, Phar::PHPS +--SKIPIF-- + +--ENV-- +SCRIPT_NAME=/frontcontroller15.php/a.php +REQUEST_URI=/frontcontroller15.php/a.php +--FILE_EXTERNAL-- +frontcontroller8.phar +--EXPECTHEADERS-- +Content-type: text/html +--EXPECT-- + +<?php function hio(){} + + + diff --git a/ext/phar/tests/frontcontroller16.phpt b/ext/phar/tests/frontcontroller16.phpt new file mode 100644 index 0000000000..e68a0c0e39 --- /dev/null +++ b/ext/phar/tests/frontcontroller16.phpt @@ -0,0 +1,14 @@ +--TEST-- +Phar front controller mime type override, Phar::PHP +--SKIPIF-- + +--ENV-- +SCRIPT_NAME=/frontcontroller16.php/a.phps +REQUEST_URI=/frontcontroller16.php/a.phps +--FILE_EXTERNAL-- +frontcontroller8.phar +--EXPECTHEADERS-- +Content-type: text/html +--EXPECT-- +hio1 + diff --git a/ext/phar/tests/frontcontroller17.phpt b/ext/phar/tests/frontcontroller17.phpt new file mode 100644 index 0000000000..3aea1262de --- /dev/null +++ b/ext/phar/tests/frontcontroller17.phpt @@ -0,0 +1,15 @@ +--TEST-- +Phar front controller mime type unknown +--SKIPIF-- + +--ENV-- +SCRIPT_NAME=/frontcontroller17.php/fronk.gronk +REQUEST_URI=/frontcontroller17.php/fronk.gronk +--FILE_EXTERNAL-- +frontcontroller8.phar +--EXPECTHEADERS-- +Content-type: application/octet-stream +Content-length: 4 +--EXPECT-- +hio3 + diff --git a/ext/phar/tests/frontcontroller6.phar b/ext/phar/tests/frontcontroller6.phar new file mode 100644 index 0000000000..e3b6bb86a1 Binary files /dev/null and b/ext/phar/tests/frontcontroller6.phar differ diff --git a/ext/phar/tests/frontcontroller6.phar.inc b/ext/phar/tests/frontcontroller6.phar.inc new file mode 100644 index 0000000000..5c900eb603 --- /dev/null +++ b/ext/phar/tests/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/frontcontroller7.phar b/ext/phar/tests/frontcontroller7.phar new file mode 100644 index 0000000000..79672809b4 Binary files /dev/null and b/ext/phar/tests/frontcontroller7.phar differ diff --git a/ext/phar/tests/frontcontroller7.phar.inc b/ext/phar/tests/frontcontroller7.phar.inc new file mode 100644 index 0000000000..684970263e --- /dev/null +++ b/ext/phar/tests/frontcontroller7.phar.inc @@ -0,0 +1,12 @@ +setStub(' null)); +echo "oops did not run\n"; +var_dump($_ENV, $_SERVER); +__HALT_COMPILER();'); +?> diff --git a/ext/phar/tests/frontcontroller8.phar b/ext/phar/tests/frontcontroller8.phar new file mode 100644 index 0000000000..213fe35d4d Binary files /dev/null and b/ext/phar/tests/frontcontroller8.phar differ diff --git a/ext/phar/tests/frontcontroller8.phar.inc b/ext/phar/tests/frontcontroller8.phar.inc new file mode 100644 index 0000000000..ccedb46e34 --- /dev/null +++ b/ext/phar/tests/frontcontroller8.phar.inc @@ -0,0 +1,13 @@ +setStub(' "foo/bar", "phps" => Phar::PHP, "php" => Phar::PHPS)); +echo "oops did not run\n"; +var_dump($_ENV, $_SERVER); +__HALT_COMPILER();'); +?>