Annotation of embedaddon/php/ext/mbstring/tests/bug43840.phpt, revision 1.1

1.1     ! misho       1: --TEST--
        !             2: Test mb_strpos() function : mb_strpos bounds check is byte count rather than a character count
        !             3: --SKIPIF--
        !             4: <?php
        !             5: extension_loaded('mbstring') or die('skip');
        !             6: function_exists('mb_strpos') or die("skip mb_strpos() is not available in this build");
        !             7: ?>
        !             8: --FILE--
        !             9: <?php
        !            10: /* Prototype  : int mb_strpos(string $haystack, string $needle [, int $offset [, string $encoding]])
        !            11:  * Description: Find position of first occurrence of a string within another 
        !            12:  * Source code: ext/mbstring/mbstring.c
        !            13:  */
        !            14: 
        !            15: /*
        !            16:  * mb_strpos bounds check is byte count rather than a character count:
        !            17:  * The multibyte string should be returning the same results as the ASCII string.
        !            18:  * Multibyte string was not returning error message until offset was passed the
        !            19:  * byte count of the string. Should return error message when passed character count.
        !            20:  */
        !            21: 
        !            22: $offsets = array(20, 21, 22, 53, 54);
        !            23: $string_mb = base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII=');
        !            24: $needle = base64_decode('44CC');
        !            25: 
        !            26: foreach($offsets as $i) {
        !            27:        echo "\n-- Offset is $i --\n";
        !            28:        echo "--Multibyte String:--\n";
        !            29:        var_dump( mb_strpos($string_mb, $needle, $i, 'UTF-8') );
        !            30:        echo"--ASCII String:--\n";
        !            31:        var_dump(mb_strpos(b'This is na English ta', b'a', $i));
        !            32: }
        !            33: ?>
        !            34: --EXPECTF--
        !            35: -- Offset is 20 --
        !            36: --Multibyte String:--
        !            37: int(20)
        !            38: --ASCII String:--
        !            39: int(20)
        !            40: 
        !            41: -- Offset is 21 --
        !            42: --Multibyte String:--
        !            43: bool(false)
        !            44: --ASCII String:--
        !            45: bool(false)
        !            46: 
        !            47: -- Offset is 22 --
        !            48: --Multibyte String:--
        !            49: 
        !            50: Warning: mb_strpos(): Offset not contained in string in %s on line %d
        !            51: bool(false)
        !            52: --ASCII String:--
        !            53: 
        !            54: Warning: mb_strpos(): Offset not contained in string in %s on line %d
        !            55: bool(false)
        !            56: 
        !            57: -- Offset is 53 --
        !            58: --Multibyte String:--
        !            59: 
        !            60: Warning: mb_strpos(): Offset not contained in string in %s on line %d
        !            61: bool(false)
        !            62: --ASCII String:--
        !            63: 
        !            64: Warning: mb_strpos(): Offset not contained in string in %s on line %d
        !            65: bool(false)
        !            66: 
        !            67: -- Offset is 54 --
        !            68: --Multibyte String:--
        !            69: 
        !            70: Warning: mb_strpos(): Offset not contained in string in %s on line %d
        !            71: bool(false)
        !            72: --ASCII String:--
        !            73: 
        !            74: Warning: mb_strpos(): Offset not contained in string in %s on line %d
        !            75: bool(false)

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