diff options
author | Nicolas Oelgart <nicolas.oelgart@atrapalo.com> | 2020-02-17 14:29:12 +0100 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2020-02-25 10:26:03 +0100 |
commit | aa79a22d32f31dbc5343f8191e925aa07447c3ec (patch) | |
tree | 85a3cbefa474cb428161242ad54c1631a654c980 /ext/pcre/tests | |
parent | bb6e2a1615a54bc2986c782a2541289fd33a1bbb (diff) | |
download | php-git-aa79a22d32f31dbc5343f8191e925aa07447c3ec.tar.gz |
Add preg_last_error_msg() function
Provides the last PCRE error as a human-readable message, similar
to functionality existing in other extensions, such as
json_last_error_msg().
Closes GH-5185.
Diffstat (limited to 'ext/pcre/tests')
-rw-r--r-- | ext/pcre/tests/errors01.phpt | 15 | ||||
-rw-r--r-- | ext/pcre/tests/errors02.phpt | 12 | ||||
-rw-r--r-- | ext/pcre/tests/errors03.phpt | 13 | ||||
-rw-r--r-- | ext/pcre/tests/errors04.phpt | 26 | ||||
-rw-r--r-- | ext/pcre/tests/errors05.phpt | 18 | ||||
-rw-r--r-- | ext/pcre/tests/errors06.phpt | 11 |
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) |