Files
newznab-tmux/misc/testing/Tests/test_regex.php
T
2016-07-14 08:47:39 +02:00

55 lines
1.4 KiB
PHP

<?php
//
// This script is used to test the regular expressions identified
// within a nntmux database are valid.
//
// by l2g
//
require_once realpath(dirname(dirname(dirname(__DIR__))) . DIRECTORY_SEPARATOR . 'bootstrap.php');
use nntmux\db\Settings;
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 = array(
"empty" => "",
"illformed" => "[](9()))))))))) [34543/34]",
"simple" => '"data.mp3',
);
$db = new Settings();
# 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);