mirror of
https://github.com/erusev/parsedown.git
synced 2025-09-03 03:42:38 +02:00
faster check substr at beginning of string
This commit is contained in:
@@ -1533,7 +1533,7 @@ class Parsedown
|
||||
unset($Element['attributes'][$att]);
|
||||
}
|
||||
# dump onevent attribute
|
||||
elseif (preg_match('/^on/i', $att))
|
||||
elseif (self::striAtStart($att, 'on'))
|
||||
{
|
||||
unset($Element['attributes'][$att]);
|
||||
}
|
||||
@@ -1551,7 +1551,7 @@ class Parsedown
|
||||
|
||||
foreach ($this->safeLinksWhitelist as $scheme)
|
||||
{
|
||||
if (stripos($Element['attributes'][$attribute], $scheme) === 0)
|
||||
if (self::striAtStart($Element['attributes'][$attribute], $scheme))
|
||||
{
|
||||
$safe = true;
|
||||
|
||||
@@ -1584,6 +1584,20 @@ class Parsedown
|
||||
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')
|
||||
{
|
||||
if (isset(self::$instances[$name]))
|
||||
|
Reference in New Issue
Block a user