powermail icon indicating copy to clipboard operation
powermail copied to clipboard

different validation of urls in JavaScript and PHP

Open lisardo2 opened this issue 4 years ago • 2 comments

The javascript validation of a valid url allows url with or without protocol:

all the following urls are valid:

  • http://www.domain.de
  • https://www.domain.de
  • www.domain.de

But the validation via php throws an error with "www.domain.de".

The reason is a change in behavior since php 5.2.1.

up to php 5.2.1 FILTER_VALIDATE_URL allows urls with or without protocol but from PHP 5.2.1 FILTER_VALIDATE_URL uses implicit FILTER_FLAG_SCHEME_REQUIRED and FILTER_FLAG_HOST_REQUIRED.

/Classes/Domain/Validator/StringValidator.php line 42 - 45. https://www.php.net/manual/de/filter.filters.validate.php (changelog)

It seems there is no way to disable the use of FILTER_FLAG_SCHEME_REQUIRED: https://stackoverflow.com/questions/45240033/what-is-use-of-filter-flag-scheme-required-and-filter-flag-host-required-flags-f

--

So the only way to fix this misbahavior ist to add a test for the protocol to the javascript.

lisardo2 avatar Mar 03 '20 12:03 lisardo2

You could check if parsley allows such an option in a newer version: http://parsleyjs.org/

einpraegsam avatar Mar 29 '20 18:03 einpraegsam

This is still a problem. PHP throws error without https://, powermail doesnt.

TYPO3 12.4.15 powermail 12.3.1 PHP 8.1

For input type url this could help: <input pattern="https://.*" ...

eBornstein avatar Jun 07 '24 07:06 eBornstein