Annotation of embedaddon/php/ext/phar/tests/create_path_error.phpt, revision 1.1.1.2

1.1       misho       1: --TEST--
                      2: Phar: create with illegal path
                      3: --SKIPIF--
                      4: <?php if (!extension_loaded("phar")) die("skip"); ?>
                      5: <?php if (!extension_loaded("spl")) die("skip SPL not available"); ?>
                      6: --INI--
                      7: phar.readonly=0
                      8: phar.require_hash=1
                      9: --FILE--
                     10: <?php
                     11: 
                     12: $fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
                     13: $pname = 'phar://' . $fname;
                     14: 
                     15: @unlink($fname);
                     16: 
                     17: file_put_contents($pname . '/a.php?', "query");
                     18: file_put_contents($pname . '/b.php?bla', "query");
                     19: 
                     20: var_dump(file_get_contents($pname . '/a.php'));
                     21: var_dump(file_get_contents($pname . '/b.php'));
                     22: 
                     23: function error_handler($errno, $errmsg)
                     24: {
1.1.1.2 ! misho      25:        echo "Error: $errmsg";
1.1       misho      26: }
                     27: 
                     28: set_error_handler('error_handler');
                     29: 
1.1.1.2 ! misho      30: $count = 0;
        !            31: $checks = array(
        !            32:     '/', '.', '../', 'a/..', 'a/', 'b//a.php', 
        !            33:     "Font\xE5\x84\xB7\xE9\xBB\x91pro.ttf", //two valid multi-byte characters
        !            34:     "\xF0\x9F\x98\x8D.ttf", // valid 4 byte char - smiling face with heart-shaped eyes
        !            35:     "Font\xE9\xBBpro.ttf", //Invalid multi-byte character - missing last byte
        !            36:     "Font\xBB\x91pro.ttf",   //Invalid multi-byte character - missing first byte
        !            37:     "Font\xC0\xAFpro.ttf",   //Invalid multi-byte character - invalid first byte
        !            38:     "Font\xF0\x80\x90\x90pro.ttf",   //Invalid multi-byte character - surrogate pair code point
        !            39:     "\xFC\x81\x81\x81\x81pro.ttf", //RFC 3629 limited char points to 0000-10FFFF aka 5 byte utf-8 not valid
        !            40: );
1.1       misho      41: foreach($checks as $check)
                     42: {
1.1.1.2 ! misho      43:        $count++;
        !            44:        echo "$count:";
1.1       misho      45:        file_put_contents($pname . '/' . $check, "error");
1.1.1.2 ! misho      46:        echo "\n";
1.1       misho      47: }
                     48: 
                     49: $phar = new Phar($fname);
                     50: $checks = array("a\0");
                     51: foreach($checks as $check)
                     52: {
                     53:        try
                     54:        {
                     55:                $phar[$check] = 'error';
                     56:        }
                     57:        catch(Exception $e)
                     58:        {
                     59:                echo 'Exception: ' . $e->getMessage() . "\n";
                     60:        }
                     61: }
                     62: 
                     63: ?>
                     64: ===DONE===
                     65: --CLEAN--
                     66: <?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
                     67: --EXPECTF--
                     68: string(5) "query"
                     69: string(5) "query"
1.1.1.2 ! misho      70: 1:Error: file_put_contents(phar://%s//): failed to open stream: phar error: file "" in phar "%s" cannot be empty
        !            71: 2:Error: file_put_contents(phar://%s/.): failed to open stream: phar error: file "" in phar "%s" cannot be empty
        !            72: 3:Error: file_put_contents(phar://%s/../): failed to open stream: phar error: file "" in phar "%s" cannot be empty
        !            73: 4:Error: file_put_contents(phar://%s/a/..): failed to open stream: phar error: file "" in phar "%s" cannot be empty
        !            74: 5:
        !            75: 6:
        !            76: 7:
        !            77: 8:
        !            78: 9:Error: file_put_contents(phar:///%s): failed to open stream: phar error: invalid path "%s" contains illegal character
        !            79: 10:Error: file_put_contents(phar:///%s): failed to open stream: phar error: invalid path "%s" contains illegal character
        !            80: 11:Error: file_put_contents(phar:///%s): failed to open stream: phar error: invalid path "%s" contains illegal character
        !            81: 12:Error: file_put_contents(phar:///%s): failed to open stream: phar error: invalid path "%s" contains illegal character
        !            82: 13:Error: file_put_contents(phar:///%s): failed to open stream: phar error: invalid path "%s" contains illegal character
1.1       misho      83: Exception: Entry a does not exist and cannot be created: phar error: invalid path "a" contains illegal character
                     84: ===DONE===
1.1.1.2 ! misho      85: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>