]> granicus.if.org Git - php/commitdiff
improve rewrite callback support, add test for callback that does not return string...
authorGreg Beaver <cellog@php.net>
Wed, 23 Apr 2008 17:18:28 +0000 (17:18 +0000)
committerGreg Beaver <cellog@php.net>
Wed, 23 Apr 2008 17:18:28 +0000 (17:18 +0000)
ext/phar/phar_object.c
ext/phar/tests/files/frontcontroller18.phar [new file with mode: 0644]
ext/phar/tests/files/frontcontroller18.phar.inc [new file with mode: 0644]
ext/phar/tests/frontcontroller33.phpt [new file with mode: 0644]

index 35b8cbd53e982987d037ca34bbf2f6d0421c51c2..a8fcc6b0f20bdac47d3966b0b320662466b6e451 100755 (executable)
@@ -647,7 +647,7 @@ PHP_METHOD(Phar, webPhar)
                        }
                        return;
                }
-               if (!retval_ptr) {
+               if (!fci.retval_ptr_ptr || !retval_ptr) {
                        if (free_pathinfo) {
                                efree(path_info);
                        }
@@ -657,8 +657,13 @@ PHP_METHOD(Phar, webPhar)
                switch (Z_TYPE_P(retval_ptr)) {
                        case IS_STRING :
                                efree(entry);
-                               entry = Z_STRVAL_P(retval_ptr);
-                               entry_len = Z_STRLEN_P(retval_ptr);
+                               if (fci.retval_ptr_ptr != &retval_ptr) {
+                                       entry = estrndup(Z_STRVAL_PP(fci.retval_ptr_ptr), Z_STRLEN_PP(fci.retval_ptr_ptr));
+                                       entry_len = Z_STRLEN_PP(fci.retval_ptr_ptr);
+                               } else {
+                                       entry = Z_STRVAL_P(retval_ptr);
+                                       entry_len = Z_STRLEN_P(retval_ptr);
+                               }
                                break;
                        case IS_BOOL :
                                phar_do_403(entry, entry_len TSRMLS_CC);
@@ -667,9 +672,6 @@ PHP_METHOD(Phar, webPhar)
                                }
                                zend_bailout();
                                return;
-                       case IS_NULL :
-                               /* just use what we have now */
-                               break;
                        default:
                                efree(retval_ptr);
                                if (free_pathinfo) {
diff --git a/ext/phar/tests/files/frontcontroller18.phar b/ext/phar/tests/files/frontcontroller18.phar
new file mode 100644 (file)
index 0000000..b24d619
Binary files /dev/null and b/ext/phar/tests/files/frontcontroller18.phar differ
diff --git a/ext/phar/tests/files/frontcontroller18.phar.inc b/ext/phar/tests/files/frontcontroller18.phar.inc
new file mode 100644 (file)
index 0000000..847a713
--- /dev/null
@@ -0,0 +1,19 @@
+<?php
+@unlink(dirname(__FILE__) . '/frontcontroller18.phar');
+$a = new Phar(dirname(__FILE__) . '/frontcontroller18.phar');
+$a['index.php'] = '<?php
+echo "hi";
+';
+$a->setStub('<?php
+function s($a)
+{
+}
+try {
+Phar::webPhar("test.phar", "/index.php", null, array(), "s");
+} catch (Exception $e) {
+die($e->getMessage() . "\n");
+}
+echo "oops did not run\n";
+var_dump($_ENV, $_SERVER);
+__HALT_COMPILER();');
+?>
diff --git a/ext/phar/tests/frontcontroller33.phpt b/ext/phar/tests/frontcontroller33.phpt
new file mode 100644 (file)
index 0000000..e1bc2a7
--- /dev/null
@@ -0,0 +1,13 @@
+--TEST--
+Phar front controller with valid callback that does not return any value
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--ENV--
+SCRIPT_NAME=/frontcontroller33.php
+REQUEST_URI=/frontcontroller33.php
+--EXPECTHEADERS--
+Content-type: text/html
+--FILE_EXTERNAL--
+files/frontcontroller18.phar
+--EXPECTF--
+phar error: rewrite callback must return a string or false
\ No newline at end of file