-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Add preg_last_error_msg() function #5185
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
9e3bc1f
Add preg_last_error_msg() function
90c5e3c
Use php_pcre_error_code type where applicable
bd1b4af
Use tab
232a57c
Add preg_last_error_msg types
85222fb
Add stub
b8cc885
Add separate error message for offset errors
cc63e34
Add malformed utf-8 offset test
3e3957c
Add generated arginfo
aa907c6
Fix test name
35a51b4
Improve error message
48a79ed
Check for JIT support
66bebb6
Small fixes
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.