Revert "refactor(RichObjectStrings): Only log error if key or value is not string in validator"

This reverts commit fd156d3408.

Signed-off-by: Joas Schilling <coding@schilljs.com>
pull/52062/head
Joas Schilling 2025-04-09 08:35:56 +07:00
parent edeccc897f
commit 8358a7f769
No known key found for this signature in database
GPG Key ID: F72FA5B49FFA96B0
2 changed files with 7 additions and 4 deletions

@ -10,8 +10,6 @@ namespace OC\RichObjectStrings;
use OCP\RichObjectStrings\Definitions;
use OCP\RichObjectStrings\InvalidObjectExeption;
use OCP\RichObjectStrings\IValidator;
use OCP\Server;
use Psr\Log\LoggerInterface;
/**
* Class Validator
@ -81,10 +79,10 @@ class Validator implements IValidator {
foreach ($parameter as $key => $value) {
if (!is_string($key)) {
Server::get(LoggerInterface::class)->error('Object for placeholder ' . $placeholder . ' is invalid, key ' . $key . ' is not a string');
throw new InvalidObjectExeption('Object for placeholder ' . $placeholder . ' is invalid, key ' . $key . ' is not a string');
}
if (!is_string($value)) {
Server::get(LoggerInterface::class)->error('Object for placeholder ' . $placeholder . ' is invalid, value ' . $value . ' for key ' . $key . ' is not a string');
throw new InvalidObjectExeption('Object for placeholder ' . $placeholder . ' is invalid, value ' . $value . ' for key ' . $key . ' is not a string');
}
}
}

@ -10,6 +10,7 @@ namespace Test\RichObjectStrings;
use OC\RichObjectStrings\Validator;
use OCP\RichObjectStrings\Definitions;
use OCP\RichObjectStrings\InvalidObjectExeption;
use Test\TestCase;
class ValidatorTest extends TestCase {
@ -36,6 +37,9 @@ class ValidatorTest extends TestCase {
]);
$this->addToAssertionCount(2);
$this->expectException(InvalidObjectExeption::class);
$this->expectExceptionMessage('Object for placeholder string1 is invalid, value 123 for key key is not a string');
$v->validate('test {string1} test.', [
'string1' => [
'type' => 'user',
@ -45,6 +49,7 @@ class ValidatorTest extends TestCase {
],
]);
$this->expectExceptionMessage('Object for placeholder string1 is invalid, key 456 is not a string');
$v->validate('test {string1} test.', [
'string1' => [
'type' => 'user',