Made url validation of less restrictive
authorMarcel Werk <burntime@woltlab.com>
Wed, 31 Jul 2024 14:30:59 +0000 (16:30 +0200)
committerMarcel Werk <burntime@woltlab.com>
Wed, 31 Jul 2024 14:30:59 +0000 (16:30 +0200)
ref https://www.woltlab.com/community/thread/306975-validierung-der-url-im-urlformfield/

wcfsetup/install/files/lib/system/form/builder/field/UrlFormField.class.php

index ebd9e9580212bf194694e385d1027f0457109ddf..29bbb3b7cd20e9632152db4038be4cc4dcffa7c4 100644 (file)
@@ -2,9 +2,10 @@
 
 namespace wcf\system\form\builder\field;
 
+use Laminas\Diactoros\Exception\InvalidArgumentException;
+use Laminas\Diactoros\Uri;
 use wcf\data\language\Language;
 use wcf\system\form\builder\field\validation\FormFieldValidationError;
-use wcf\util\Url;
 
 /**
  * Implementation of a form field to enter a url.
@@ -52,15 +53,19 @@ class UrlFormField extends TextFormField
         if ($this->isRequired() && ($this->getValue() === null || $this->getValue() === '')) {
             $this->addValidationError(new FormFieldValidationError('empty'));
         } elseif ($this->getValue() !== null && $this->getValue() !== '') {
-            if (!Url::is($text)) {
+            try {
+                new Uri($text);
+            } catch (InvalidArgumentException) {
                 $this->addValidationError(new FormFieldValidationError(
                     'invalid',
                     'wcf.form.field.url.error.invalid',
                     ['language' => $language]
                 ));
-            } else {
-                parent::validateText($text, $language);
+
+                return;
             }
+
+            parent::validateText($text, $language);
         }
     }