[icinga-checkins] icinga.org: icingaweb2/feature/announce-banner-11198: NavigationItemForm: Validate that urls with credentials contain a protocol

git at icinga.org git at icinga.org
Fri Oct 28 17:48:31 CEST 2016


Module: icingaweb2
Branch: feature/announce-banner-11198
Commit: 6492f3c105a0fc97db91e6933f94b9c7001ff228
URL:    https://git.icinga.org/?p=icingaweb2.git;a=commit;h=6492f3c105a0fc97db91e6933f94b9c7001ff228

Author: Noah Hilverling <noah.hilverling at netways.de>
Date:   Fri Oct 28 10:36:13 2016 +0200

NavigationItemForm: Validate that urls with credentials contain a protocol

refs #12890

---

 application/forms/Navigation/NavigationItemForm.php |   18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/application/forms/Navigation/NavigationItemForm.php b/application/forms/Navigation/NavigationItemForm.php
index 4f2df85..44f1648 100644
--- a/application/forms/Navigation/NavigationItemForm.php
+++ b/application/forms/Navigation/NavigationItemForm.php
@@ -56,6 +56,24 @@ class NavigationItemForm extends Form
                     'The url of this navigation item. Leave blank if only the name should be displayed.'
                     . ' For urls with username and password and for all external urls,'
                     . ' make sure to prepend an appropriate protocol identifier (e.g. http://example.tld)'
+                ),
+                'validators'    => array(
+                    array(
+                        'Callback',
+                        false,
+                        array(
+                            'callback' => function($url) {
+                                // Matches if the given url contains obviously
+                                // a username but not any protocol identifier
+                                return !preg_match('#^((?=[^/@]).)+ at .*$#', $url);
+                            },
+                            'messages' => array(
+                                'callbackValue' => $this->translate(
+                                    'Missing protocol identifier'
+                                )
+                            )
+                        )
+                    )
                 )
             )
         );



More information about the icinga-checkins mailing list