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 $safeLinksWhitelist = array(
|
||||
'http://',
|
||||
'https://',
|
||||
'/',
|
||||
'ftp://',
|
||||
'ftps://'
|
||||
);
|
||||
|
||||
#
|
||||
# Lines
|
||||
#
|
||||
@ -1262,10 +1270,23 @@ class Parsedown
|
||||
$Element['attributes']['title'] = $Definition['title'];
|
||||
}
|
||||
|
||||
if ( $this->safeLinksEnabled && preg_match("/^(\/|https?:\/\/|ftps?:\/\/)/ui", $Element['attributes']['href']) === 0 )
|
||||
if ( $this->safeLinksEnabled )
|
||||
{
|
||||
$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['text'] = htmlspecialchars($Element['text'], ENT_QUOTES);
|
||||
|
Loading…
Reference in New Issue
Block a user