summaryrefslogtreecommitdiff
path: root/ext/pcre/tests
diff options
context:
space:
mode:
Diffstat (limited to 'ext/pcre/tests')
-rw-r--r--ext/pcre/tests/errors01.phpt15
-rw-r--r--ext/pcre/tests/errors02.phpt12
-rw-r--r--ext/pcre/tests/errors03.phpt13
-rw-r--r--ext/pcre/tests/errors04.phpt26
-rw-r--r--ext/pcre/tests/errors05.phpt18
-rw-r--r--ext/pcre/tests/errors06.phpt11
6 files changed, 95 insertions, 0 deletions
diff --git a/ext/pcre/tests/errors01.phpt b/ext/pcre/tests/errors01.phpt
new file mode 100644
index 0000000000..c239309c11
--- /dev/null
+++ b/ext/pcre/tests/errors01.phpt
@@ -0,0 +1,15 @@
+--TEST--
+Test preg_split() function : error conditions - Recursion limit exhausted
+--INI--
+pcre.recursion_limit=1
+--FILE--
+<?php
+
+var_dump(preg_last_error_msg() === 'No error');
+preg_split('/(\d*)/', 'ab2c3u');
+var_dump(preg_last_error_msg() === 'Recursion limit exhausted');
+
+?>
+--EXPECT--
+bool(true)
+bool(true)
diff --git a/ext/pcre/tests/errors02.phpt b/ext/pcre/tests/errors02.phpt
new file mode 100644
index 0000000000..d350bae705
--- /dev/null
+++ b/ext/pcre/tests/errors02.phpt
@@ -0,0 +1,12 @@
+--TEST--
+Test preg_split() function : error conditions - Malformed UTF-8
+--FILE--
+<?php
+
+var_dump(preg_split('/a/u', "a\xff"));
+var_dump(preg_last_error_msg() === 'Malformed UTF-8 characters, possibly incorrectly encoded');
+
+?>
+--EXPECT--
+bool(false)
+bool(true)
diff --git a/ext/pcre/tests/errors03.phpt b/ext/pcre/tests/errors03.phpt
new file mode 100644
index 0000000000..1f519cb599
--- /dev/null
+++ b/ext/pcre/tests/errors03.phpt
@@ -0,0 +1,13 @@
+--TEST--
+Test preg_match() function : error conditions - Internal error
+--FILE--
+<?php
+
+var_dump(preg_match('/', 'Hello world'));
+var_dump(preg_last_error_msg() === 'Internal error');
+
+?>
+--EXPECTF--
+Warning: preg_match(): No ending delimiter '/' found in %s on line %d
+bool(false)
+bool(true)
diff --git a/ext/pcre/tests/errors04.phpt b/ext/pcre/tests/errors04.phpt
new file mode 100644
index 0000000000..340b084098
--- /dev/null
+++ b/ext/pcre/tests/errors04.phpt
@@ -0,0 +1,26 @@
+--TEST--
+Test preg_match_all() function : error conditions - Backtracking limit
+--SKIPIF--
+<?php
+if (@preg_match_all('/\p{N}/', '0123456789', $dummy) === false) {
+ die("skip no support for \p support PCRE library");
+}
+?>
+--INI--
+pcre.backtrack_limit=2
+pcre.jit=0
+--FILE--
+<?php
+
+var_dump(preg_match_all('/.*\p{N}/', '0123456789', $dummy));
+var_dump(preg_last_error_msg() === 'Backtrack limit exhausted');
+
+var_dump(preg_match_all('/\p{Nd}/', '0123456789', $dummy));
+var_dump(preg_last_error_msg() === 'No error');
+
+?>
+--EXPECT--
+bool(false)
+bool(true)
+int(10)
+bool(true)
diff --git a/ext/pcre/tests/errors05.phpt b/ext/pcre/tests/errors05.phpt
new file mode 100644
index 0000000000..13fabc4f30
--- /dev/null
+++ b/ext/pcre/tests/errors05.phpt
@@ -0,0 +1,18 @@
+--TEST--
+Test preg_match() function : error conditions - jit stacklimit exhausted
+--SKIPIF--
+<?php
+if (ini_get('pcre.jit') === false) {
+ die("skip no jit built");
+}
+?>
+--INI--
+pcre.jit=1
+--FILE--
+<?php
+var_dump(preg_match('/^(foo)+$/', str_repeat('foo', 1024*8192)));
+var_dump(preg_last_error_msg() === 'JIT stack limit exhausted');
+?>
+--EXPECT--
+bool(false)
+bool(true)
diff --git a/ext/pcre/tests/errors06.phpt b/ext/pcre/tests/errors06.phpt
new file mode 100644
index 0000000000..8e78244233
--- /dev/null
+++ b/ext/pcre/tests/errors06.phpt
@@ -0,0 +1,11 @@
+--TEST--
+Test preg_match() function : error conditions - Malformed UTF-8 offset
+--FILE--
+<?php
+preg_match('/a/u', "\xE3\x82\xA2", $m, 0, 1);
+var_dump(preg_last_error() === PREG_BAD_UTF8_OFFSET_ERROR);
+var_dump(preg_last_error_msg() === 'The offset did not correspond to the beginning of a valid UTF-8 code point');
+?>
+--EXPECT--
+bool(true)
+bool(true)