-
-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding preg_replace to special cases functions (#72)
* Adding preg_replace to special cases functions
- Loading branch information
Showing
8 changed files
with
135 additions
and
9 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains 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 |
---|---|---|
|
@@ -1074,4 +1074,5 @@ | |
'json_decode', | ||
'apc_fetch', | ||
'apcu_fetch', | ||
'preg_replace', | ||
]; |
This file contains 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 |
---|---|---|
|
@@ -6,5 +6,6 @@ | |
return [ | ||
'json_decode', | ||
'apc_fetch', | ||
'apcu_fetch' | ||
'apcu_fetch', | ||
'preg_replace', | ||
]; |
This file contains 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 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,21 @@ | ||
<?php | ||
|
||
namespace Safe; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Safe\Exceptions\PcreException; | ||
|
||
class SpecialCasesTest extends TestCase | ||
{ | ||
public function testPregReplace() | ||
{ | ||
require_once __DIR__.'/../../lib/special_cases.php'; | ||
require_once __DIR__.'/../../lib/Exceptions/SafeExceptionInterface.php'; | ||
require_once __DIR__.'/../../lib/Exceptions/AbstractSafeException.php'; | ||
require_once __DIR__.'/../../lib/Exceptions/PcreException.php'; | ||
|
||
$this->expectException(PcreException::class); | ||
$this->expectExceptionMessage('PREG_BAD_UTF8_ERROR: Invalid UTF8 character'); | ||
preg_replace("/([\s,]+)/u", "foo", "\xc3\x28"); | ||
} | ||
} |
This file contains 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,21 @@ | ||
<?php | ||
|
||
|
||
namespace Safe\Exceptions; | ||
|
||
class PcreException extends \Exception implements SafeExceptionInterface | ||
{ | ||
public static function createFromPhpError(): self | ||
{ | ||
$errorMap = [ | ||
PREG_INTERNAL_ERROR => 'PREG_INTERNAL_ERROR: Internal error', | ||
PREG_BACKTRACK_LIMIT_ERROR => 'PREG_BACKTRACK_LIMIT_ERROR: Backtrack limit reached', | ||
PREG_RECURSION_LIMIT_ERROR => 'PREG_RECURSION_LIMIT_ERROR: Recursion limit reached', | ||
PREG_BAD_UTF8_ERROR => 'PREG_BAD_UTF8_ERROR: Invalid UTF8 character', | ||
PREG_BAD_UTF8_OFFSET_ERROR => 'PREG_BAD_UTF8_OFFSET_ERROR', | ||
PREG_JIT_STACKLIMIT_ERROR => 'PREG_JIT_STACKLIMIT_ERROR', | ||
]; | ||
$errMsg = $errorMap[preg_last_error()] ?? 'Unknown PCRE error: '.preg_last_error(); | ||
return new static($errMsg, \preg_last_error()); | ||
} | ||
} |
This file contains 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 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