Fix json template validation bugs

This commit is contained in:
Dennis Eichhorn 2019-02-25 23:56:58 +01:00
parent e60952e75b
commit 6e2bfebc60
2 changed files with 28 additions and 26 deletions

View File

@ -1,16 +1,19 @@
{
"name": "[a-z]+",
"fields": {
".*": {
"name": "[a-z]+",
"type": ".+",
".*?default": "1|0",
".*?null": "1|0",
".*?primary": "1|0",
".*?unique": "1|0",
".*?autoincrement": "1|0",
".*?foreignTable": "[a-z]+",
".*?foreignKey": "[a-z]+"
".*": {
"name": "[a-z\\_]+",
"fields": {
".*": {
"name": "[a-z\\_]+",
"type": "[A-Z0-9\\(\\)]+",
".*?default": ".*",
".*?null": "1|0",
".*?primary": "1|0",
".*?unique": "1|0",
".*?autoincrement": "1|0",
".*?foreignTable": "[a-z\\_]+",
".*?foreignKey": "[a-z\\_]+",
".*?annotations": ".*"
}
}
}
}

View File

@ -14,6 +14,7 @@ declare(strict_types=1);
namespace phpOMS\Validation\Base;
use phpOMS\Utils\StringUtils;
use phpOMS\Validation\ValidatorAbstract;
/**
@ -193,28 +194,26 @@ abstract class Json extends ValidatorAbstract
}
foreach ($source as $sPath => $sValue) {
$sourceIsValid = false;
$foundPath = false;
$isValidValue = false;
$pathFound = false;
foreach ($validPaths as $tPath => $tValue) {
if (!$foundPath
&& ($tPath === $sPath
|| \preg_match('~' . \str_replace('/', '\\/', $tPath) . '~', $sPath) === 1)
if ($tPath === $sPath
|| \preg_match('~' . \str_replace('/', '\\/', $tPath) . '~', $sPath) === 1
) {
$foundPath = true;
}
$pathFound = true;
$sValue = StringUtils::stringify($sValue);
if (($tPath === $sPath
|| \preg_match('~' . \str_replace('/', '\\/', $tPath) . '~', $sPath) === 1)
&& ($tValue === $sValue
if (($tValue === $sValue
|| \preg_match('~' . ((string) $tValue) . '~', (string) $sValue) === 1)
) {
$sourceIsValid = true;
break;
) {
$isValidValue = true;
break;
}
}
}
if (!$sourceIsValid && $foundPath) {
if (!$isValidValue && $pathFound) {
return false;
}
}