Add unit tests for #429 and improve regexp efficiency

This commit is contained in:
Kijin Sung 2016-04-05 19:46:09 +09:00
parent c6ed0bdd28
commit 45d17eb9bb
2 changed files with 11 additions and 3 deletions

View file

@ -79,7 +79,7 @@ class MediaFilter
*/
public static function formatPrefix($prefix)
{
$prefix = preg_match('@^(https?:)?//(.*)$@i', $prefix, $matches) ? $matches[2] : $prefix;
$prefix = preg_match('@^(?:https?:)?//(.*)$@i', $prefix, $matches) ? $matches[1] : $prefix;
if (strpos($prefix, '/') === false)
{
$prefix .= '/';
@ -117,7 +117,7 @@ class MediaFilter
{
$result[] = str_replace('\*\.', '[a-z0-9-]+\.', preg_quote($domain, '%'));
}
return '%^(https?:)?//(' . implode('|', $result) . ')%';
return '%^(?:https?:)?//(' . implode('|', $result) . ')%';
}
/**
@ -150,7 +150,7 @@ class MediaFilter
{
$result[] = str_replace('\*\.', '[a-z0-9-]+\.', preg_quote($domain, '%'));
}
return '%^(https?:)?//(' . implode('|', $result) . ')%';
return '%^(?:https?:)?//(' . implode('|', $result) . ')%';
}
/**