FAQ
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

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupphp-cvs @
categoriesphp
postedMar 8, '08 at 11:51a
activeMar 8, '08 at 11:51a
posts1
users1
websitephp.net

1 user in discussion

Nuno Lopes: 1 post

People

Translate

site design / logo © 2018 Grokbase