Unverified Commit 4b68814a authored by alexpott's avatar alexpott
Browse files

Issue #3029336 by andypost: Properly deprecate check_url()

parent a9745363
......@@ -211,7 +211,7 @@ function valid_email_address($mail) {
* Drupal\Core\Template\Attribute, call
* \Drupal\Component\Utility\UrlHelper::stripDangerousProtocols() instead.
*
* @deprecated in Drupal 8.0.x-dev, will be removed before Drupal 9.0.0.
* @deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0.
* Use UrlHelper::stripDangerousProtocols() or UrlHelper::filterBadProtocol()
* instead. UrlHelper::stripDangerousProtocols() can be used in conjunction
* with \Drupal\Component\Render\FormattableMarkup and an @variable
......@@ -225,6 +225,7 @@ function valid_email_address($mail) {
* @see https://www.drupal.org/node/2560027
*/
function check_url($uri) {
@trigger_error(__FUNCTION__ . '() is deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use UrlHelper::stripDangerousProtocols() or UrlHelper::filterBadProtocol() instead. See https://www.drupal.org/node/2560027', E_USER_DEPRECATED);
return Html::escape(UrlHelper::stripDangerousProtocols($uri));
}
......
......@@ -48,10 +48,21 @@ public function testBadProtocolStripping() {
$url = 'javascript:http://www.example.com/?x=1&y=2';
$expected_plain = 'http://www.example.com/?x=1&y=2';
$expected_html = 'http://www.example.com/?x=1&y=2';
$this->assertIdentical(check_url($url), $expected_html, 'check_url() filters a URL and encodes it for HTML.');
$this->assertIdentical(UrlHelper::filterBadProtocol($url), $expected_html, '\Drupal\Component\Utility\UrlHelper::filterBadProtocol() filters a URL and encodes it for HTML.');
$this->assertIdentical(UrlHelper::stripDangerousProtocols($url), $expected_plain, '\Drupal\Component\Utility\UrlHelper::stripDangerousProtocols() filters a URL and returns plain text.');
}
/**
* Tests deprecation of the check_url() function.
*
* @group legacy
* @expectedDeprecation check_url() is deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use UrlHelper::stripDangerousProtocols() or UrlHelper::filterBadProtocol() instead. See https://www.drupal.org/node/2560027
*/
public function testCheckUrl() {
$url = 'javascript:http://www.example.com/?x=1&y=2';
$expected_html = 'http://www.example.com/?x=1&y=2';
$this->assertSame($expected_html, check_url($url));
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment