]> granicus.if.org Git - php/commitdiff
new tests, fix mime type overrides (all web front controller primary features are...
authorGreg Beaver <cellog@php.net>
Sat, 5 Jan 2008 06:14:43 +0000 (06:14 +0000)
committerGreg Beaver <cellog@php.net>
Sat, 5 Jan 2008 06:14:43 +0000 (06:14 +0000)
14 files changed:
ext/phar/phar_object.c
ext/phar/tests/frontcontroller11.phpt
ext/phar/tests/frontcontroller12.phpt [new file with mode: 0644]
ext/phar/tests/frontcontroller13.phpt [new file with mode: 0644]
ext/phar/tests/frontcontroller14.phpt [new file with mode: 0644]
ext/phar/tests/frontcontroller15.phpt [new file with mode: 0644]
ext/phar/tests/frontcontroller16.phpt [new file with mode: 0644]
ext/phar/tests/frontcontroller17.phpt [new file with mode: 0644]
ext/phar/tests/frontcontroller6.phar [new file with mode: 0644]
ext/phar/tests/frontcontroller6.phar.inc [new file with mode: 0644]
ext/phar/tests/frontcontroller7.phar [new file with mode: 0644]
ext/phar/tests/frontcontroller7.phar.inc [new file with mode: 0644]
ext/phar/tests/frontcontroller8.phar [new file with mode: 0644]
ext/phar/tests/frontcontroller8.phar.inc [new file with mode: 0644]

index 0849559a9b7cf39a152efe035b3f1a0d6521b786..fb863c91bf346df7f4950d7fba27c637e8271ae3 100755 (executable)
@@ -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);
index 5160d7127324f1d4389c182f068067f4df844f90..3da89977cba44dd68e1b06b8ccaba0fac73c5f7c 100644 (file)
@@ -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--
diff --git a/ext/phar/tests/frontcontroller12.phpt b/ext/phar/tests/frontcontroller12.phpt
new file mode 100644 (file)
index 0000000..8054fa5
--- /dev/null
@@ -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
\ No newline at end of file
diff --git a/ext/phar/tests/frontcontroller13.phpt b/ext/phar/tests/frontcontroller13.phpt
new file mode 100644 (file)
index 0000000..eb3c01f
--- /dev/null
@@ -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
\ No newline at end of file
diff --git a/ext/phar/tests/frontcontroller14.phpt b/ext/phar/tests/frontcontroller14.phpt
new file mode 100644 (file)
index 0000000..0a7e61a
--- /dev/null
@@ -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
diff --git a/ext/phar/tests/frontcontroller15.phpt b/ext/phar/tests/frontcontroller15.phpt
new file mode 100644 (file)
index 0000000..21fb069
--- /dev/null
@@ -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">&lt;?php&nbsp;</span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">hio</span><span style="color: #007700">(){}</span>
+</span>
+</code>
+
diff --git a/ext/phar/tests/frontcontroller16.phpt b/ext/phar/tests/frontcontroller16.phpt
new file mode 100644 (file)
index 0000000..e68a0c0
--- /dev/null
@@ -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
+
diff --git a/ext/phar/tests/frontcontroller17.phpt b/ext/phar/tests/frontcontroller17.phpt
new file mode 100644 (file)
index 0000000..3aea126
--- /dev/null
@@ -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
+
diff --git a/ext/phar/tests/frontcontroller6.phar b/ext/phar/tests/frontcontroller6.phar
new file mode 100644 (file)
index 0000000..e3b6bb8
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 (file)
index 0000000..5c900eb
--- /dev/null
@@ -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();');
+?>
diff --git a/ext/phar/tests/frontcontroller7.phar b/ext/phar/tests/frontcontroller7.phar
new file mode 100644 (file)
index 0000000..7967280
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 (file)
index 0000000..6849702
--- /dev/null
@@ -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();');
+?>
diff --git a/ext/phar/tests/frontcontroller8.phar b/ext/phar/tests/frontcontroller8.phar
new file mode 100644 (file)
index 0000000..213fe35
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 (file)
index 0000000..ccedb46
--- /dev/null
@@ -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();');
+?>