From 0a3fa5c77bc0ddd8b6cd38726edcd00f2de6ab0c Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Wed, 16 Apr 2025 12:06:57 +0900 Subject: [PATCH] Prevent unnecessary length calculation if minlength/maxlength are not set --- .../parsers/dbquery/VariableBase.php | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/common/framework/parsers/dbquery/VariableBase.php b/common/framework/parsers/dbquery/VariableBase.php index 5d20ffe00..0c5f984dd 100644 --- a/common/framework/parsers/dbquery/VariableBase.php +++ b/common/framework/parsers/dbquery/VariableBase.php @@ -450,14 +450,28 @@ class VariableBase } // Check minimum and maximum lengths. - $length = is_scalar($value) ? iconv_strlen($value, 'UTF-8') : (is_countable($value) ? count($value) : 1); - if (isset($this->minlength) && $this->minlength > 0 && $length < $this->minlength) + $length = null; + if (isset($this->minlength) && $this->minlength > 0) { - throw new \Rhymix\Framework\Exceptions\QueryError('Variable ' . $this->var . ' for column ' . $column . ' must contain no less than ' . $this->minlength . ' characters'); + if ($length === null) + { + $length = is_scalar($value) ? mb_strlen($value, 'UTF-8') : (is_countable($value) ? count($value) : 1); + } + if ($length < $this->minlength) + { + throw new \Rhymix\Framework\Exceptions\QueryError('Variable ' . $this->var . ' for column ' . $column . ' must contain no less than ' . $this->minlength . ' characters'); + } } - if (isset($this->maxlength) && $this->maxlength > 0 && $length > $this->maxlength) + if (isset($this->maxlength) && $this->maxlength > 0) { - throw new \Rhymix\Framework\Exceptions\QueryError('Variable ' . $this->var . ' for column ' . $column . ' must contain no more than ' . $this->maxlength . ' characters'); + if ($length === null) + { + $length = is_scalar($value) ? mb_strlen($value, 'UTF-8') : (is_countable($value) ? count($value) : 1); + } + if ($length > $this->maxlength) + { + throw new \Rhymix\Framework\Exceptions\QueryError('Variable ' . $this->var . ' for column ' . $column . ' must contain no more than ' . $this->maxlength . ' characters'); + } } }