cvs: php-src /ext/pcre/tests 007.phpt invalid_utf8_offset.phpt

From: Date: Sat, 08 Mar 2008 11:51:03 +0000
Subject: cvs: php-src /ext/pcre/tests 007.phpt invalid_utf8_offset.phpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-48956@lists.php.net to get a copy of this message
nlopess Sat Mar 8 11:51:03 2008 UTC Modified files: /php-src/ext/pcre/tests 007.phpt invalid_utf8_offset.phpt Log: add new tests http://cvs.php.net/viewvc.cgi/php-src/ext/pcre/tests/007.phpt?r1=1.1&r2=1.2&diff_format=u Index: php-src/ext/pcre/tests/007.phpt diff -u /dev/null php-src/ext/pcre/tests/007.phpt:1.2 --- /dev/null Sat Mar 8 11:51:03 2008 +++ php-src/ext/pcre/tests/007.phpt Sat Mar 8 11:51:03 2008 @@ -0,0 +1,59 @@ +--TEST-- +preg_replace_callback() with callback that modifies subject string +--SKIPIF-- +<?php +if (@preg_match('/./u', '') === false) { + die('skip no utf8 support in PCRE library'); +} +?> +--FILE-- +<?php + +function evil($x) { + global $txt; + $txt[3] = "\xFF"; + var_dump($x); + return $x[0]; +} + +$txt = "ola123"; +var_dump(preg_replace_callback('#.#u', 'evil', $txt)); +var_dump($txt); +var_dump(preg_last_error() == PREG_NO_ERROR); + +var_dump(preg_replace_callback('#.#u', 'evil', $txt)); +var_dump(preg_last_error() == PREG_BAD_UTF8_ERROR); + +echo "Done!\n"; +?> +--EXPECT-- +array(1) { + [0]=> + string(1) "o" +} +array(1) { + [0]=> + string(1) "l" +} +array(1) { + [0]=> + string(1) "a" +} +array(1) { + [0]=> + string(1) "1" +} +array(1) { + [0]=> + string(1) "2" +} +array(1) { + [0]=> + string(1) "3" +} +string(6) "ola123" +string(6) "olaÿ23" +bool(true) +NULL +bool(true) +Done! http://cvs.php.net/viewvc.cgi/php-src/ext/pcre/tests/invalid_utf8_offset.phpt?r1=1.1&r2=1.2&diff_format=u Index: php-src/ext/pcre/tests/invalid_utf8_offset.phpt diff -u /dev/null php-src/ext/pcre/tests/invalid_utf8_offset.phpt:1.2 --- /dev/null Sat Mar 8 11:51:03 2008 +++ php-src/ext/pcre/tests/invalid_utf8_offset.phpt Sat Mar 8 11:51:03 2008 @@ -0,0 +1,35 @@ +--TEST-- +preg_replace() and invalid UTF8 offset +--SKIPIF-- +<?php +if (@preg_match('/./u', '') === false) { + die('skip no utf8 support in PCRE library'); +} +?> +--FILE-- +<?php + +$string = "\xc3\xa9 uma string utf8 bem formada"; + +var_dump(preg_match('~.*~u', $string, $m, 0, 1)); +var_dump($m); +var_dump(preg_last_error() == PREG_BAD_UTF8_OFFSET_ERROR); + +var_dump(preg_match('~.*~u', $string, $m, 0, 2)); +var_dump($m); +var_dump(preg_last_error() == PREG_NO_ERROR); + +echo "Done\n"; +?> +--EXPECT-- +int(0) +array(0) { +} +bool(true) +int(1) +array(1) { + [0]=> + string(28) " uma string utf8 bem formada" +} +bool(true) +Done

« previous php.cvs (#48956) next »