Skip to content

Commit ac7b662

Browse files
authored
Merge pull request #2348 from nextcloud/fix/1360-textmaxlength-enforcement
Client-side only enforcement of textMaxLength
2 parents 68dc7b2 + a4b6065 commit ac7b662

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

lib/Service/RowService.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@ private function cleanupAndValidateData(RowDataInput $data, array $columns, ?int
343343
$column = $this->getColumnFromColumnsArray($columnId, $columns);
344344

345345
if ($column) {
346+
$this->validateColumnValueLimits($column, $entry['value']);
346347
$columnBusiness = $this->columnsHelper->getColumnBusinessObject($column);
347348
$columnBusiness->validateValue($entry['value'], $column, $this->userId, $tableId, $rowId);
348349
}
@@ -865,4 +866,27 @@ public function importRow(Table $table, array $row): int {
865866
throw new InternalError('userMigrationImport insert error: ' . $e->getMessage());
866867
}
867868
}
869+
870+
/**
871+
* validate column value constraints (textMaxLength, numberMin, numberMax).
872+
*
873+
* @param Column $column
874+
* @param mixed $value
875+
*
876+
* @throws BadRequestError
877+
*/
878+
private function validateColumnValueLimits(Column $column, $value): void {
879+
$textMaxLength = $column->getTextMaxLength();
880+
if ($textMaxLength !== null && is_string($value) && mb_strlen($value) > $textMaxLength) {
881+
throw new BadRequestError('Value for column ' . $column->getTitle() . ' exceeds maximum length of ' . $textMaxLength);
882+
}
883+
$numberMin = $column->getNumberMin();
884+
if ($numberMin !== null && is_numeric($value) && $value < $numberMin) {
885+
throw new BadRequestError('Value for column ' . $column->getTitle() . ' is less than minimum allowed value of ' . $numberMin);
886+
}
887+
$numberMax = $column->getNumberMax();
888+
if ($numberMax !== null && is_numeric($value) && $value > $numberMax) {
889+
throw new BadRequestError('Value for column ' . $column->getTitle() . ' exceeds maximum allowed value of ' . $numberMax);
890+
}
891+
}
868892
}

0 commit comments

Comments
 (0)