Skip to content

Commit

Permalink
fix create new CO
Browse files Browse the repository at this point in the history
  • Loading branch information
Ioannis committed Sep 12, 2025
1 parent 3ecbf9c commit 18264dc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
27 changes: 14 additions & 13 deletions app/src/Lib/Traits/ValidationTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,13 +237,14 @@ public function validateIncreaseStep(string $value, int $step, array $context) {
/**
* Determine if a string submitted from a form is valid input.
*
* @since COmanage Registry v5.0.0
* @param string $value Value to validate
* @param array $context Optional validation context; accepts 'type' of 'html' (may be extended to include 'email', 'url' etc.
* @param string $value Value to validate
* @param array $options
* @param array $context Optional validation context; accepts 'type' of 'html'
* @return mixed True if $value validates, or an error string otherwise
*@since COmanage Registry v5.0.0
*/

public function validateInput(string $value, array $context) {
public function validateInput(string $value, array $options = [], array $context = []): bool|string {
// By default, we'll accept anything except < and >. Arguably, we should accept
// anything at all for input (and filter only on output), but this was agreed to
// as an extra "line of defense" against unsanitized HTML output. Where user supplied
Expand All @@ -252,8 +253,8 @@ public function validateInput(string $value, array $context) {
// XXX we previously supported 'flags' and 'invalidchars' as arguments, do we still need to?
// CFM-152 review the logic here

if(!empty($context['type'])) {
switch($context['type']) {
if(!empty($options['type'])) {
switch($options['type']) {
case 'html':
// We are accepting HTML input. We will mostly pass it all through and ensure
// properly sanitized output. However, we can do some very rudimentary checking for script tags.
Expand Down Expand Up @@ -284,7 +285,7 @@ public function validateInput(string $value, array $context) {
}

// We require at least one non-whitespace character (CO-1551)
$notBlankValidation = $this->validateNotBlank($value, $context);
$notBlankValidation = $this->validateNotBlank($value, $options);
if ($notBlankValidation !== true) {
return $notBlankValidation;
}
Expand All @@ -296,25 +297,25 @@ public function validateInput(string $value, array $context) {
/**
* Validate the maximum length of a field.
*
* @param string $value Value to validate
* @param array $columnMetadata
* @param array $context Validation context, which must include the schema definition
* @param string $value Value to validate
* @param array $options
* @param array $context Validation context, which must include the schema definition
*
* @return bool|string True if $value validates, or an error string otherwise
* @since COmanage Registry v5.0.0
*/

public function validateMaxLength(string $value, array $columnMetadata, array $context): bool|string {
public function validateMaxLength(string $value, array $options = [], array $context = []): bool|string {
// We use our own so we can introspect the field's max length from the
// provided table schema object, and use our own error message (without
// having to copy it to every table definition).

// Text has no limit.
if ($columnMetadata['column']['type'] === 'text') {
if ($options['column']['type'] === 'text') {
return true;
}

$maxLength = $columnMetadata['column']['length'];
$maxLength = $options['column']['length'];

if(!empty($value) && mb_strlen($value) > $maxLength) {
return __d('error', 'input.length', [$maxLength]);
Expand Down
2 changes: 1 addition & 1 deletion app/src/Model/Table/MostlyStaticPagesTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ public function validationDefault(Validator $validator): Validator {
$validator->notEmptyString('context');

$validator->add('body', [
'filter' => ['rule' => ['validateInput',['type' => 'html']],
'filter' => ['rule' => ['validateInput', ['type' => 'html']],
'provider' => 'table']
]);
$validator->allowEmptyString('body');
Expand Down

0 comments on commit 18264dc

Please sign in to comment.