mirror of
https://github.com/erusev/parsedown.git
synced 2023-08-10 21:13:06 +03:00
safeMode will either apply all sanitisation techniques to an element or none (note that encoding HTML entities is done regardless because it speaks to character context, and that the only attributes/elements we should permit are the ones we actually mean to create)
This commit is contained in:
parent
b1e5aebaf6
commit
bbb7687f31
@ -1422,7 +1422,10 @@ class Parsedown
|
||||
|
||||
protected function element(array $Element)
|
||||
{
|
||||
$Element = $this->sanitiseElement($Element);
|
||||
if ($this->safeMode)
|
||||
{
|
||||
$Element = $this->sanitiseElement($Element);
|
||||
}
|
||||
|
||||
$markup = '<'.$Element['name'];
|
||||
|
||||
@ -1543,27 +1546,23 @@ class Parsedown
|
||||
|
||||
protected function filterUnsafeUrlInAttribute(array $Element, $attribute)
|
||||
{
|
||||
if ($this->safeMode)
|
||||
foreach ($this->safeLinksWhitelist as $scheme)
|
||||
{
|
||||
foreach ($this->safeLinksWhitelist as $scheme)
|
||||
if (self::striAtStart($Element['attributes'][$attribute], $scheme))
|
||||
{
|
||||
if (self::striAtStart($Element['attributes'][$attribute], $scheme))
|
||||
{
|
||||
return $Element;
|
||||
}
|
||||
return $Element;
|
||||
}
|
||||
|
||||
$Element['attributes'][$attribute] = preg_replace_callback(
|
||||
'/[^\/#?&=%]++/',
|
||||
function (array $match)
|
||||
{
|
||||
return urlencode($match[0]);
|
||||
},
|
||||
$Element['attributes'][$attribute]
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
$Element['attributes'][$attribute] = preg_replace_callback(
|
||||
'/[^\/#?&=%]++/',
|
||||
function (array $match)
|
||||
{
|
||||
return urlencode($match[0]);
|
||||
},
|
||||
$Element['attributes'][$attribute]
|
||||
);
|
||||
|
||||
return $Element;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user