mirror of
https://github.com/php/php-src.git
synced 2024-12-14 20:33:36 +08:00
new tests, fix mime type overrides (all web front controller primary features are now tested and working for regular phar files)
This commit is contained in:
parent
e864f512bb
commit
efc22a3726
@ -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);
|
||||
|
@ -1,5 +1,5 @@
|
||||
--TEST--
|
||||
Phar front controller rewrite array invalid
|
||||
Phar front controller mime type extension is not a string
|
||||
--SKIPIF--
|
||||
<?php if (!extension_loaded("phar")) die("skip"); ?>
|
||||
--ENV--
|
||||
|
17
ext/phar/tests/frontcontroller12.phpt
Normal file
17
ext/phar/tests/frontcontroller12.phpt
Normal file
@ -0,0 +1,17 @@
|
||||
--TEST--
|
||||
Phar front controller mime type unknown int
|
||||
--SKIPIF--
|
||||
<?php if (!extension_loaded("phar")) die("skip"); ?>
|
||||
--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
|
17
ext/phar/tests/frontcontroller13.phpt
Normal file
17
ext/phar/tests/frontcontroller13.phpt
Normal file
@ -0,0 +1,17 @@
|
||||
--TEST--
|
||||
Phar front controller mime type not string/int
|
||||
--SKIPIF--
|
||||
<?php if (!extension_loaded("phar")) die("skip"); ?>
|
||||
--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
|
14
ext/phar/tests/frontcontroller14.phpt
Normal file
14
ext/phar/tests/frontcontroller14.phpt
Normal file
@ -0,0 +1,14 @@
|
||||
--TEST--
|
||||
Phar front controller mime type override, other
|
||||
--SKIPIF--
|
||||
<?php if (!extension_loaded("phar")) die("skip"); ?>
|
||||
--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
|
17
ext/phar/tests/frontcontroller15.phpt
Normal file
17
ext/phar/tests/frontcontroller15.phpt
Normal file
@ -0,0 +1,17 @@
|
||||
--TEST--
|
||||
Phar front controller mime type override, Phar::PHPS
|
||||
--SKIPIF--
|
||||
<?php if (!extension_loaded("phar")) die("skip"); ?>
|
||||
--ENV--
|
||||
SCRIPT_NAME=/frontcontroller15.php/a.php
|
||||
REQUEST_URI=/frontcontroller15.php/a.php
|
||||
--FILE_EXTERNAL--
|
||||
frontcontroller8.phar
|
||||
--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>
|
||||
|
14
ext/phar/tests/frontcontroller16.phpt
Normal file
14
ext/phar/tests/frontcontroller16.phpt
Normal file
@ -0,0 +1,14 @@
|
||||
--TEST--
|
||||
Phar front controller mime type override, Phar::PHP
|
||||
--SKIPIF--
|
||||
<?php if (!extension_loaded("phar")) die("skip"); ?>
|
||||
--ENV--
|
||||
SCRIPT_NAME=/frontcontroller16.php/a.phps
|
||||
REQUEST_URI=/frontcontroller16.php/a.phps
|
||||
--FILE_EXTERNAL--
|
||||
frontcontroller8.phar
|
||||
--EXPECTHEADERS--
|
||||
Content-type: text/html
|
||||
--EXPECT--
|
||||
hio1
|
||||
|
15
ext/phar/tests/frontcontroller17.phpt
Normal file
15
ext/phar/tests/frontcontroller17.phpt
Normal file
@ -0,0 +1,15 @@
|
||||
--TEST--
|
||||
Phar front controller mime type unknown
|
||||
--SKIPIF--
|
||||
<?php if (!extension_loaded("phar")) die("skip"); ?>
|
||||
--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
|
||||
|
BIN
ext/phar/tests/frontcontroller6.phar
Normal file
BIN
ext/phar/tests/frontcontroller6.phar
Normal file
Binary file not shown.
12
ext/phar/tests/frontcontroller6.phar.inc
Normal file
12
ext/phar/tests/frontcontroller6.phar.inc
Normal file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
@unlink(dirname(__FILE__) . '/frontcontroller6.phar');
|
||||
$a = new Phar(dirname(__FILE__) . '/frontcontroller6.phar');
|
||||
$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" => 100));
|
||||
echo "oops did not run\n";
|
||||
var_dump($_ENV, $_SERVER);
|
||||
__HALT_COMPILER();');
|
||||
?>
|
BIN
ext/phar/tests/frontcontroller7.phar
Normal file
BIN
ext/phar/tests/frontcontroller7.phar
Normal file
Binary file not shown.
12
ext/phar/tests/frontcontroller7.phar.inc
Normal file
12
ext/phar/tests/frontcontroller7.phar.inc
Normal file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
@unlink(dirname(__FILE__) . '/frontcontroller7.phar');
|
||||
$a = new Phar(dirname(__FILE__) . '/frontcontroller7.phar');
|
||||
$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();');
|
||||
?>
|
BIN
ext/phar/tests/frontcontroller8.phar
Normal file
BIN
ext/phar/tests/frontcontroller8.phar
Normal file
Binary file not shown.
13
ext/phar/tests/frontcontroller8.phar.inc
Normal file
13
ext/phar/tests/frontcontroller8.phar.inc
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
@unlink(dirname(__FILE__) . '/frontcontroller8.phar');
|
||||
$a = new Phar(dirname(__FILE__) . '/frontcontroller8.phar');
|
||||
$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();');
|
||||
?>
|
Loading…
Reference in New Issue
Block a user