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\\_]+",
".*": { "fields": {
"name": "[a-z]+", ".*": {
"type": ".+", "name": "[a-z\\_]+",
".*?default": "1|0", "type": "[A-Z0-9\\(\\)]+",
".*?null": "1|0", ".*?default": ".*",
".*?primary": "1|0", ".*?null": "1|0",
".*?unique": "1|0", ".*?primary": "1|0",
".*?autoincrement": "1|0", ".*?unique": "1|0",
".*?foreignTable": "[a-z]+", ".*?autoincrement": "1|0",
".*?foreignKey": "[a-z]+" ".*?foreignTable": "[a-z\\_]+",
".*?foreignKey": "[a-z\\_]+",
".*?annotations": ".*"
}
} }
} }
} }

View File

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