mirror of
https://github.com/getgrav/grav.git
synced 2026-07-07 17:53:02 +02:00
Reverted validation: strict fix as it breaks sites, see [#1273]
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
1. [](#bugfix)
|
||||
* Fixed issue with search plugins not being able to switch between page translations
|
||||
* Fixed issues with `Pages::baseRoute()` not picking up active language reliably
|
||||
* Reverted `validation: strict` fix as it breaks sites, see [#1273](https://github.com/getgrav/grav/issues/1273)
|
||||
|
||||
# v1.6.21
|
||||
## 02/11/2020
|
||||
|
||||
@@ -53,7 +53,7 @@ class BlueprintSchema extends BlueprintSchemaBase implements ExportInterface
|
||||
public function validate(array $data)
|
||||
{
|
||||
try {
|
||||
$messages = $this->validateArray($data, $this->nested, $this->items['']['form'] ?? []);
|
||||
$messages = $this->validateArray($data, $this->nested);
|
||||
|
||||
} catch (\RuntimeException $e) {
|
||||
throw (new ValidationException($e->getMessage(), $e->getCode(), $e))->setMessages();
|
||||
@@ -129,11 +129,10 @@ class BlueprintSchema extends BlueprintSchemaBase implements ExportInterface
|
||||
/**
|
||||
* @param array $data
|
||||
* @param array $rules
|
||||
* @param array $parent
|
||||
* @return array
|
||||
* @throws \RuntimeException
|
||||
*/
|
||||
protected function validateArray(array $data, array $rules, array $parent)
|
||||
protected function validateArray(array $data, array $rules)
|
||||
{
|
||||
$messages = $this->checkRequired($data, $rules);
|
||||
|
||||
@@ -151,8 +150,8 @@ class BlueprintSchema extends BlueprintSchemaBase implements ExportInterface
|
||||
$messages += Validation::validate($child, $rule);
|
||||
} elseif (\is_array($child) && \is_array($val)) {
|
||||
// Array has been defined in blueprints.
|
||||
$messages += $this->validateArray($child, $val, $rule ?? []);
|
||||
} elseif (isset($parent['validation']) && $parent['validation'] === 'strict') {
|
||||
$messages += $this->validateArray($child, $val);
|
||||
} elseif (isset($rules['validation']) && $rules['validation'] === 'strict') {
|
||||
// Undefined/extra item.
|
||||
throw new \RuntimeException(sprintf('%s is not defined in blueprints', $key));
|
||||
}
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Grav\Common\Data\Blueprint;
|
||||
|
||||
/**
|
||||
* Class InstallCommandTest
|
||||
*/
|
||||
class BlueprintTest extends \Codeception\TestCase\Test
|
||||
{
|
||||
/**
|
||||
*/
|
||||
public function testValidateStrict()
|
||||
{
|
||||
$blueprint = $this->loadBlueprint('strict');
|
||||
|
||||
$blueprint->validate(['test' => 'string']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testValidateStrict
|
||||
* @expectedException Grav\Common\Data\ValidationException
|
||||
*/
|
||||
public function testValidateStrictRequired()
|
||||
{
|
||||
$blueprint = $this->loadBlueprint('strict');
|
||||
|
||||
$blueprint->validate([]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testValidateStrict
|
||||
* @expectedException Grav\Common\Data\ValidationException
|
||||
*/
|
||||
public function testValidateStrictExtra()
|
||||
{
|
||||
$blueprint = $this->loadBlueprint('strict');
|
||||
|
||||
$blueprint->validate(['test' => 'string', 'wrong' => 'field']);
|
||||
die();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $filename
|
||||
* @return Blueprint
|
||||
*/
|
||||
protected function loadBlueprint($filename)
|
||||
{
|
||||
$blueprint = new Blueprint('strict');
|
||||
$blueprint->setContext(dirname(__DIR__, 3). '/data/blueprints');
|
||||
$blueprint->load()->init();
|
||||
|
||||
return $blueprint;
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
form:
|
||||
validation: strict
|
||||
|
||||
fields:
|
||||
test:
|
||||
type: text
|
||||
label: Test
|
||||
validate:
|
||||
required: true
|
||||
Reference in New Issue
Block a user