aboutsummaryrefslogtreecommitdiff
path: root/app/fn
diff options
context:
space:
mode:
authorvincent-peugnet <v.peugnet@free.fr>2020-04-27 13:35:29 +0200
committervincent-peugnet <v.peugnet@free.fr>2020-04-28 20:21:34 +0200
commitcba95c5eb19a33654a6f0995c6f9e0885b7afc20 (patch)
treea334a0fa3c074f44fe41a4114ea1853ac7f6c0e3 /app/fn
parentc832f91ca41490f69f478045c86038f9ef4a5cb5 (diff)
downloadwcms-cba95c5eb19a33654a6f0995c6f9e0885b7afc20.tar.gz
wcms-cba95c5eb19a33654a6f0995c6f9e0885b7afc20.zip
fix password max size
add error in hydrate
Diffstat (limited to 'app/fn')
-rw-r--r--app/fn/fn.php24
1 files changed, 17 insertions, 7 deletions
diff --git a/app/fn/fn.php b/app/fn/fn.php
index f20c8c6..afadae8 100644
--- a/app/fn/fn.php
+++ b/app/fn/fn.php
@@ -90,19 +90,29 @@ function arrayclean($input)
/**
* Clean string from characters outside `[0-9a-z-_]` and troncate it
* @param string $input
- * @param int $max lenght to trucate id
+ * @param int $max minmum input length to trucate id
+ * @param int $min minimum output length to send error message
* @return string output formated id
+ * @throws \RuntimeException If ID length is inverior to minimal length
*/
-function idclean(string $input, int $max = Wcms\Model::MAX_ID_LENGTH): string
+function idclean(string $input, int $max = Wcms\Model::MAX_ID_LENGTH, int $min = 0): string
{
+ $regex = '%[^a-z0-9-_]%';
$input = urldecode($input);
- $search = ['é', 'à', 'è', 'ç', 'ù', 'ï', 'î', ' '];
- $replace = ['e', 'a', 'e', 'c', 'u', 'i', 'i', '-'];
- $input = str_replace($search, $replace, $input);
- $input = preg_replace('%[^a-z0-9-_+]%', '', strtolower(trim($input)));
+ if (preg_match($regex, $input)) {
+ $search = ['é', 'à', 'è', 'ç', 'ù', 'ï', 'î', ' '];
+ $replace = ['e', 'a', 'e', 'c', 'u', 'i', 'i', '-'];
+ $input = str_replace($search, $replace, $input);
+
+ $input = preg_replace($regex, '', strtolower(trim($input)));
+
+ $input = substr($input, 0, $max);
+ }
- $input = substr($input, 0, $max);
+ if (strlen($input) < $min) {
+ throw new \RuntimeException("Id length cant be inferior to $min");
+ }
return $input;
}