0

I try to create a link field to let user input external link (e.g http://www.example.com:1000/test=https://www.check.com, however, when I display the link in a view or display on front page, I find the url become http://www.example.com:1000/test=https%3A//www.check.com so make the url not work. Does anyone know how to avoid?

Regards, Tony

Tony
  • 31
  • 3

1 Answers1

0

Hello Tony this is standard URL behavior, not specific to Drupal. In general, it is bad practice to use a : in a URL.

My personal recommendation would be to adjust the expected input for your test parameter to not include the https:// portion of the input URL.

Here is a good reference: A Complete Guide To URL Escape Characters

Isaiah Nixon
  • 320
  • 1
  • 10
  • Drupal does url encode the link, though, so this answer doesn't really addressed the question. Some 3rd party server may require a malformed URL, in which case it may be necessary to work around Drupal's encoding. – aaronbauman Apr 18 '22 at 19:06
  • That's fair, the URL encoding could be happening in one of two places: PHP, or Twig. My first bet would be Twig, you could override the template that is displaying the link and use the [raw filter](https://twig.symfony.com/doc/2.x/filters/raw.html) to force the improperly formatted output. If it's Drupal's URL class doing the encoding you may need to pass a new variable to Twig which is explicitly [decoded](https://stackoverflow.com/questions/1756862/url-decoding-in-php). – Isaiah Nixon Apr 18 '22 at 20:13