diff options
author | Nuno Lopes <nlopess@php.net> | 2008-03-08 11:50:20 +0000 |
---|---|---|
committer | Nuno Lopes <nlopess@php.net> | 2008-03-08 11:50:20 +0000 |
commit | 0d0a7a432aff15332c1e003e2db8685dcf00ccee (patch) | |
tree | bffb07267cd6aee11998f5550c953e38137b9258 | |
parent | 579e46dd762a98fc284d4430401cf87978601161 (diff) | |
download | php-git-0d0a7a432aff15332c1e003e2db8685dcf00ccee.tar.gz |
add new tests
-rw-r--r-- | ext/pcre/tests/007.phpt | 59 | ||||
-rw-r--r-- | ext/pcre/tests/invalid_utf8_offset.phpt | 35 |
2 files changed, 94 insertions, 0 deletions
diff --git a/ext/pcre/tests/007.phpt b/ext/pcre/tests/007.phpt new file mode 100644 index 0000000000..776bec27b2 --- /dev/null +++ b/ext/pcre/tests/007.phpt @@ -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 index 0000000000..4e0d40caf4 --- /dev/null +++ b/ext/pcre/tests/invalid_utf8_offset.phpt @@ -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 |