Files
newznab-tmux/misc/testing/Tests/regexverify.php
T

57 lines
1.5 KiB
PHP

<?php
//
// This script is used to test the regular expressions identified
// within a nntmux database are valid.
//
// by l2g
//
require_once dirname(__DIR__, 3).DIRECTORY_SEPARATOR.'bootstrap/autoload.php';
use nntmux\db\DB;
use nntmux\Releases;
function handleError($errno, $errstr, $errfile, $errline, array $errcontext)
{
// error was suppressed with the @-operator
if (0 === error_reporting()) {
return false;
}
throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
}
set_error_handler('handleError');
$regs = [
'empty' => '',
'illformed' => '[](9()))))))))) [34543/34]',
'simple' => '"data.mp3',
];
$releases = new Releases();
$db = new DB();
// fetch enabled regular expression
$catsql = 'select ID,groupname,regex from releaseregex where status = 1';
$res = $db->query($catsql);
$total = count($res);
$errcnt = 0;
echo "\n";
foreach ($res as $regexrow) {
foreach ($regs as $regex) {
try {
$res = preg_match($regexrow['regex'], $regex);
} catch (Exception $e) {
$errcnt++;
$strerr = str_pad((int) $errcnt, 2, ' ', STR_PAD_LEFT);
echo "$strerr. id=".$regexrow['id'].
', group='.$regexrow['groupname']."\n";
echo " regex='".$regexrow['regex']."'\n";
echo ' error='.$e->getMessage()."\n\n";
break;
}
}
}
echo "Scanned $total record(s), $errcnt error(s) found.\n";
exit(($errcnt > 0) ? 1 : 0);