$url = 'http://example.com/page.php?param1='; $sanitizedUrl = \TYPO3\CMS\Core\Utility\GeneralUtility::sanitizeLocalUrl($url); // $sanitizedUrl will be 'http://example.com/page.php?param1=%3Cscript%3Ealert(%22XSS%22)%3C/script%3E'
$url = 'http://example.com/'; $sanitizedUrl = \TYPO3\CMS\Core\Utility\GeneralUtility::sanitizeLocalUrl($url); // $sanitizedUrl will be 'http://example.com/'In this example, the URL is already safe and doesn't contain any special characters that need to be encoded. The function simply returns the original URL. The sanitizeLocalUrl function is part of the TYPO3\CMS\Core\Utility package library, which is included in the TYPO3 CMS Core system.