mirror of
https://github.com/erusev/parsedown.git
synced 2024-09-19 19:41:29 +02:00
faster check substr at beginning of string
This commit is contained in:
parent
dc30cb441c
commit
2e4afde68d
@ -1533,7 +1533,7 @@ class Parsedown
|
|||||||
unset($Element['attributes'][$att]);
|
unset($Element['attributes'][$att]);
|
||||||
}
|
}
|
||||||
# dump onevent attribute
|
# dump onevent attribute
|
||||||
elseif (preg_match('/^on/i', $att))
|
elseif (self::striAtStart($att, 'on'))
|
||||||
{
|
{
|
||||||
unset($Element['attributes'][$att]);
|
unset($Element['attributes'][$att]);
|
||||||
}
|
}
|
||||||
@ -1551,7 +1551,7 @@ class Parsedown
|
|||||||
|
|
||||||
foreach ($this->safeLinksWhitelist as $scheme)
|
foreach ($this->safeLinksWhitelist as $scheme)
|
||||||
{
|
{
|
||||||
if (stripos($Element['attributes'][$attribute], $scheme) === 0)
|
if (self::striAtStart($Element['attributes'][$attribute], $scheme))
|
||||||
{
|
{
|
||||||
$safe = true;
|
$safe = true;
|
||||||
|
|
||||||
@ -1584,6 +1584,20 @@ class Parsedown
|
|||||||
return htmlspecialchars($text, $allowQuotes ? ENT_NOQUOTES : ENT_QUOTES, 'UTF-8');
|
return htmlspecialchars($text, $allowQuotes ? ENT_NOQUOTES : ENT_QUOTES, 'UTF-8');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected static function striAtStart($string, $needle)
|
||||||
|
{
|
||||||
|
$len = strlen($needle);
|
||||||
|
|
||||||
|
if ($len > strlen($string))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return strtolower(substr($string, 0, $len)) === strtolower($needle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static function instance($name = 'default')
|
static function instance($name = 'default')
|
||||||
{
|
{
|
||||||
if (isset(self::$instances[$name]))
|
if (isset(self::$instances[$name]))
|
||||||
|
Loading…
Reference in New Issue
Block a user