diff options
Diffstat (limited to 'src/Service')
| -rw-r--r-- | src/Service/FormValidation.php | 2 | ||||
| -rw-r--r-- | src/Service/Router.php | 4 | ||||
| -rw-r--r-- | src/Service/Security.php | 8 | ||||
| -rw-r--r-- | src/Service/URL.php | 27 |
4 files changed, 17 insertions, 24 deletions
diff --git a/src/Service/FormValidation.php b/src/Service/FormValidation.php index d91aa12..9f4564f 100644 --- a/src/Service/FormValidation.php +++ b/src/Service/FormValidation.php | |||
| @@ -46,7 +46,7 @@ class FormValidation | |||
| 46 | public function validate(): bool | 46 | public function validate(): bool |
| 47 | { | 47 | { |
| 48 | $this->error = ($this->callStrategy)(); // appel de la callback | 48 | $this->error = ($this->callStrategy)(); // appel de la callback |
| 49 | return empty($this->errors); | 49 | return $this->error === null; |
| 50 | } | 50 | } |
| 51 | 51 | ||
| 52 | public function getError(): string | 52 | public function getError(): string |
diff --git a/src/Service/Router.php b/src/Service/Router.php index 98cecc5..3055099 100644 --- a/src/Service/Router.php +++ b/src/Service/Router.php | |||
| @@ -347,11 +347,11 @@ class Router{ | |||
| 347 | /* -- page Menu et chemins -- */ | 347 | /* -- page Menu et chemins -- */ |
| 348 | // création d'une entrée de menu avec une URL | 348 | // création d'une entrée de menu avec une URL |
| 349 | elseif($this->request->request->has("label_input") && $this->request->request->has("url_input") && $this->request->request->has("location")){ | 349 | elseif($this->request->request->has("label_input") && $this->request->request->has("url_input") && $this->request->request->has("location")){ |
| 350 | return MenuAndPathsController::newUrlMenuEntry($this->entityManager); | 350 | return MenuAndPathsController::newUrlMenuEntry($this->entityManager, $this->request); |
| 351 | } | 351 | } |
| 352 | // suppression d'une entrée de menu avec une URL | 352 | // suppression d'une entrée de menu avec une URL |
| 353 | elseif($this->request->request->has('delete') && $this->request->request->has('x') && $this->request->request->has('y')){ // 2 params x et y sont là parce qu'on a cliqué sur une image | 353 | elseif($this->request->request->has('delete') && $this->request->request->has('x') && $this->request->request->has('y')){ // 2 params x et y sont là parce qu'on a cliqué sur une image |
| 354 | return MenuAndPathsController::deleteUrlMenuEntry($this->entityManager); | 354 | return MenuAndPathsController::deleteUrlMenuEntry($this->entityManager, $this->request); |
| 355 | } | 355 | } |
| 356 | 356 | ||
| 357 | 357 | ||
diff --git a/src/Service/Security.php b/src/Service/Security.php index 0fbd8b7..bb04535 100644 --- a/src/Service/Security.php +++ b/src/Service/Security.php | |||
| @@ -27,6 +27,12 @@ class Security | |||
| 27 | return trim(htmLawed($chaine, self::$configHtmLawed, self::$specHtmLawed)); | 27 | return trim(htmLawed($chaine, self::$configHtmLawed, self::$specHtmLawed)); |
| 28 | } | 28 | } |
| 29 | 29 | ||
| 30 | public static function validateURL(string $link): bool | ||
| 31 | { | ||
| 32 | return filter_var($link, FILTER_VALIDATE_URL) !== false // c'est une URL? | ||
| 33 | && in_array(strtolower(parse_url($link, PHP_URL_SCHEME) ?? ''), ['http', 'https'], true); // PHP_URL_SCHEME pour récupérer le protocole | ||
| 34 | } | ||
| 35 | |||
| 30 | public static function secureFileName(string $chaine): string | 36 | public static function secureFileName(string $chaine): string |
| 31 | { | 37 | { |
| 32 | // sécuriser un nom avec chemin avec basename? | 38 | // sécuriser un nom avec chemin avec basename? |
| @@ -83,7 +89,7 @@ class Security | |||
| 83 | } | 89 | } |
| 84 | 90 | ||
| 85 | // lien sans http:// | 91 | // lien sans http:// |
| 86 | function fixLinks($data) | 92 | function fixLinks(string $data): string |
| 87 | { | 93 | { |
| 88 | // 1/ | 94 | // 1/ |
| 89 | // si une adresse est de type "domaine.fr" sans le http:// devant, le comportement des navigateurs est de rechercher un fichier comme si mon adresse commençait par file:// | 95 | // si une adresse est de type "domaine.fr" sans le http:// devant, le comportement des navigateurs est de rechercher un fichier comme si mon adresse commençait par file:// |
diff --git a/src/Service/URL.php b/src/Service/URL.php index 035f572..e6f986c 100644 --- a/src/Service/URL.php +++ b/src/Service/URL.php | |||
| @@ -58,33 +58,20 @@ class URL implements \Stringable | |||
| 58 | public function setAnchor(string $anchor = ''): void | 58 | public function setAnchor(string $anchor = ''): void |
| 59 | { | 59 | { |
| 60 | if($anchor != ''){ | 60 | if($anchor != ''){ |
| 61 | $this->anchor = '#' . ltrim($anchor, '#'); | 61 | $this->anchor = '#' . rawurlencode(ltrim($anchor, '#'));// rawurlencode échappe les mêmes caractères |
| 62 | } | 62 | } |
| 63 | else{ | 63 | else{ |
| 64 | $this->anchor = ''; | 64 | $this->anchor = ''; |
| 65 | } | 65 | } |
| 66 | } | 66 | } |
| 67 | 67 | ||
| 68 | private function makeParams(): string | ||
| 69 | { | ||
| 70 | $output = ''; | ||
| 71 | $first = true; | ||
| 72 | |||
| 73 | foreach($this->params as $key => $value) { | ||
| 74 | if($first){ | ||
| 75 | $output .= '?'; | ||
| 76 | $first = false; | ||
| 77 | } | ||
| 78 | else{ | ||
| 79 | $output .= '&'; | ||
| 80 | } | ||
| 81 | $output .= $key . '=' . $value; | ||
| 82 | } | ||
| 83 | return $output; | ||
| 84 | } | ||
| 85 | |||
| 86 | public function __toString(): string | 68 | public function __toString(): string |
| 87 | { | 69 | { |
| 88 | return self::$protocol . self::$host . self::$port . self::$path . $this->makeParams() . $this->anchor; | 70 | return self::$protocol . self::$host . self::$port . self::$path |
| 71 | . ($this->params ? '?' . http_build_query($this->params) : '') | ||
| 72 | . $this->anchor; | ||
| 73 | // http_build_query change un tableau comme ['key1' => 'value 1', 'key2' => 'value 2'] | ||
| 74 | // en chaine: key1=value+1&key2=value+2 | ||
| 75 | // les caractères ", ', <, >, &, #, = et espaces sont échappés (comme avec rawurlencode pour les ancres) | ||
| 89 | } | 76 | } |
| 90 | } \ No newline at end of file | 77 | } \ No newline at end of file |
