]> granicus.if.org Git - php/commitdiff
add new tests
authorNuno Lopes <nlopess@php.net>
Sat, 8 Mar 2008 11:51:03 +0000 (11:51 +0000)
committerNuno Lopes <nlopess@php.net>
Sat, 8 Mar 2008 11:51:03 +0000 (11:51 +0000)
ext/pcre/tests/007.phpt [new file with mode: 0644]
ext/pcre/tests/invalid_utf8_offset.phpt [new file with mode: 0644]

diff --git a/ext/pcre/tests/007.phpt b/ext/pcre/tests/007.phpt
new file mode 100644 (file)
index 0000000..776bec2
--- /dev/null
@@ -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!
diff --git a/ext/pcre/tests/invalid_utf8_offset.phpt b/ext/pcre/tests/invalid_utf8_offset.phpt
new file mode 100644 (file)
index 0000000..4e0d40c
--- /dev/null
@@ -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