Skip to content

Commit

Permalink
Strip port numbers from root page domains (see contao#2553)
Browse files Browse the repository at this point in the history
Description
-----------

| Q                | A
| -----------------| ---
| Fixed issues     | Fixes contao#2214
| Docs PR or issue | -

Tested against https://regex101.com/r/jU0OrQ/2

Commits
-------

52e85cd Strip port numbers from root page domains
48a0c3c Improve the regex

Co-authored-by: Martin Auswöger <martin@auswoeger.com>
  • Loading branch information
leofeyer and ausi committed Dec 10, 2020
1 parent bc8447d commit 90caa2a
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion core-bundle/src/Resources/contao/dca/tl_page.php
Expand Up @@ -1282,7 +1282,16 @@ public function loadDns($varValue)
*/
public function checkDns($varValue)
{
return Idna::encode(preg_replace('#^(?:[a-z]+://)?([\pN\pL[\].:_-]+).*$#iu', '$1', $varValue));
if (!$varValue)
{
return '';
}

// The first part will match IPv6 addresses in square brackets. The
// second part will match domain names and IPv4 addresses.
preg_match('#^(?:[a-z]+://)?(\[[0-9a-f:]+]|[\pN\pL._-]*)#ui', $varValue, $matches);

return Idna::encode($matches[1]);
}

/**
Expand Down

0 comments on commit 90caa2a

Please sign in to comment.