mirror of
https://github.com/erusev/parsedown.git
synced 2023-08-10 21:13:06 +03:00
Customizable whitelist of schemas for safeLinks
This commit is contained in:
parent
bf5105cb1a
commit
1d4296f34d
@ -84,6 +84,14 @@ class Parsedown
|
|||||||
|
|
||||||
protected $safeLinksEnabled = true;
|
protected $safeLinksEnabled = true;
|
||||||
|
|
||||||
|
protected $safeLinksWhitelist = array(
|
||||||
|
'http://',
|
||||||
|
'https://',
|
||||||
|
'/',
|
||||||
|
'ftp://',
|
||||||
|
'ftps://'
|
||||||
|
);
|
||||||
|
|
||||||
#
|
#
|
||||||
# Lines
|
# Lines
|
||||||
#
|
#
|
||||||
@ -1262,9 +1270,22 @@ class Parsedown
|
|||||||
$Element['attributes']['title'] = $Definition['title'];
|
$Element['attributes']['title'] = $Definition['title'];
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $this->safeLinksEnabled && preg_match("/^(\/|https?:\/\/|ftps?:\/\/)/ui", $Element['attributes']['href']) === 0 )
|
if ( $this->safeLinksEnabled )
|
||||||
{
|
{
|
||||||
return;
|
$matched = false;
|
||||||
|
foreach ( $this->safeLinksWhitelist as $scheme )
|
||||||
|
{
|
||||||
|
if ( stripos($Element['attributes']['href'], $scheme) === 0 )
|
||||||
|
{
|
||||||
|
$matched = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ! $matched )
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$Element['attributes']['href'] = htmlspecialchars($Element['attributes']['href'], ENT_QUOTES);
|
$Element['attributes']['href'] = htmlspecialchars($Element['attributes']['href'], ENT_QUOTES);
|
||||||
|
Loading…
Reference in New Issue
Block a user