Annotation of embedaddon/php/ext/pcre/tests/007.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: preg_replace_callback() with callback that modifies subject string
! 3: --SKIPIF--
! 4: <?php
! 5: if (@preg_match('/./u', '') === false) {
! 6: die('skip no utf8 support in PCRE library');
! 7: }
! 8: ?>
! 9: --FILE--
! 10: <?php
! 11:
! 12: function evil($x) {
! 13: global $txt;
! 14: $txt[3] = "\xFF";
! 15: var_dump($x);
! 16: return $x[0];
! 17: }
! 18:
! 19: $txt = "ola123";
! 20: var_dump(preg_replace_callback('#.#u', 'evil', $txt));
! 21: var_dump($txt);
! 22: var_dump(preg_last_error() == PREG_NO_ERROR);
! 23:
! 24: var_dump(preg_replace_callback('#.#u', 'evil', $txt));
! 25: var_dump(preg_last_error() == PREG_BAD_UTF8_ERROR);
! 26:
! 27: echo "Done!\n";
! 28: ?>
! 29: --EXPECT--
! 30: array(1) {
! 31: [0]=>
! 32: string(1) "o"
! 33: }
! 34: array(1) {
! 35: [0]=>
! 36: string(1) "l"
! 37: }
! 38: array(1) {
! 39: [0]=>
! 40: string(1) "a"
! 41: }
! 42: array(1) {
! 43: [0]=>
! 44: string(1) "1"
! 45: }
! 46: array(1) {
! 47: [0]=>
! 48: string(1) "2"
! 49: }
! 50: array(1) {
! 51: [0]=>
! 52: string(1) "3"
! 53: }
! 54: string(6) "ola123"
! 55: string(6) "ola˙23"
! 56: bool(true)
! 57: NULL
! 58: bool(true)
! 59: Done!
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>