Skip to content

Commit

Permalink
fix: preg_last_error_msg() can be used in PHP 8.0 or later
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjis committed Jul 1, 2022
1 parent bbfd392 commit 307e194
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
8 changes: 7 additions & 1 deletion system/Autoloader/Autoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,13 @@ public function sanitizeFilename(string $filename): string
);
}
if ($result === false) {
throw new RuntimeException(preg_last_error_msg() . ' filename: "' . $filename . '"');
if (version_compare(PHP_VERSION, '8.0.0', '>=')) {
$message = preg_last_error_msg();
} else {
$message = 'Regex error. error code: ' . preg_last_error();
}

throw new RuntimeException($message . '. filename: "' . $filename . '"');
}

// Clean up our filename edges.
Expand Down
1 change: 0 additions & 1 deletion tests/system/Autoloader/AutoloaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@ public function testSanitizationFilenameEdges()
public function testSanitizationRegexError()
{
$this->expectException(RuntimeException::class);
$this->expectExceptionMessage('Malformed UTF-8 characters, possibly incorrectly encoded filename:');

$test = mb_convert_encoding('クラスファイル.php', 'EUC-JP', 'UTF-8');

Expand Down

0 comments on commit 307e194

Please sign in to comment.