How to process url from user input?
I had the same problem, so please try this:

$url_object = \Drupal::service('path.validator')-&gt;getUrlIfValid($path);
$url_object-&gt;setAbsolute();
$url = $url_object-&gt;toString();